loader

package
v0.4.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 17, 2019 License: MIT Imports: 10 Imported by: 0

Documentation

Overview

Package loader provides reading configuration from streamable data

Package loader provides reading configuration from os environment

Index

Constants

View Source
const (
	// EnvSource constant for environment variable source
	EnvSource = "env"
	// ArgsSource constant for command line args source
	ArgsSource = "args"
)

Variables

This section is empty.

Functions

func Args

func Args(prefix string) config.Loader

Args creates a loader for environment variables with prefixed keys

func Env

func Env(prefix string) config.Loader

Env creates a loader for environment variables with prefixed keys

Types

type Data

type Data struct {
	// Location is the address identifier from where the data will be read
	Location string
	// Reader creates a readable channel (io.Reader) from the provided location
	Reader Reader
	// Parser parses the data read from the channel to the database used by config.Provider
	Parser Parser
}

Data reads uses the the Location, Reader and Parser to load an instance of config.Provider

func (*Data) Load

func (s *Data) Load() (cfg config.Provider, err error)

Load uses the Location, Reader and Parser to build config.Provider.

func (*Data) Source

func (s *Data) Source() string

Source identifies that this is a data loader and which location is associated to

type EqualDelimiterParser

type EqualDelimiterParser struct {
	// Name identifier for the data that is being loaded
	Name string
	// Prefix to filter undesirable entries in slice
	Prefix string
	// Data to be parsed
	Data []string
}

EqualDelimiterParser parses Data string slice to a config.Provider, considering only prefixed variables

func (*EqualDelimiterParser) Load

func (p *EqualDelimiterParser) Load() (cfg config.Provider, err error)

Load config.Provider instance from the provided Data string slice and prefix

func (*EqualDelimiterParser) Source

func (p *EqualDelimiterParser) Source() string

Source returns an identifier for this loader

type IOReadCloser added in v0.2.0

type IOReadCloser interface {
	io.ReadCloser
}

IOReadCloser currently just wraps io.ReadCloser, allowing for mock generation when testing with io.ReadCloser

type IOReader added in v0.2.0

type IOReader interface {
	io.Reader
}

IOReader currently just wraps io.Reader, allowing for mock generation when testing with io.Reader

type Parser

type Parser interface {
	// Parse provided data to to a key value store (map[string]interface{})
	Parse(io.Reader) (map[string]interface{}, error)
}

Parser interface with function to read data to a key value store

type Reader

type Reader interface {
	// Read provides a channel to be read from the provided location. if io.Reader response is also a io.Closer, loader.Data will try to close it after parse
	Read(string) (io.Reader, error)
}

Reader interface with function to provide the readable channel (io.ReadCloser).

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL