Documentation
¶
Overview ¶
Package config provides config handling for go-micro.
Index ¶
- Variables
- func Dump(configs types.ConfigData) error
- func HasKey[T any](sections []string, key string, configs types.ConfigData) bool
- func Parse(sections []string, configs types.ConfigData, target any) error
- func ParseStruct[TParse any](sections []string, toParse TParse) (source.Data, error)
- func Read(urls []*url.URL, prependSections []string) (types.ConfigData, error)
- func SingleGet[T any](data map[string]any, key string, def T) (T, error)
Constants ¶
This section is empty.
Variables ¶
var ( // ErrUnknownPlugin happens when there's no config factory for the given plugin. ErrUnknownPlugin = errors.New("unknown config given. Did you import the config plugin?") // ErrNotExistent happens when a config key is not existent. ErrNotExistent = errors.New("no such config key") // ErrTypesDontMatch happens when types don't match during Get[T](). ErrTypesDontMatch = errors.New("config key requested type and actual type don't match") // ErrUnknownScheme happens when you didn't import the plugin for the scheme or the scheme is unknown. ErrUnknownScheme = errors.New("unknown config source scheme. Did you register the config source plugin for your scheme?") // ErrFileNotFound happens when theres no file. ErrFileNotFound = errors.New("file not found") // ErrCodecNotFound happens when the required codec is not found. ErrCodecNotFound = errors.New("marshaler for codec not found. Did you import the codec plugin for your file type?") )
Functions ¶
func Dump ¶ added in v0.1.0
func Dump(configs types.ConfigData) error
Dump is a helper function to dump configDatas to the console.
func HasKey ¶ added in v0.1.0
HasKey returns a boolean which indidcates if the given sections and key exists in the configs.
func Parse ¶
func Parse(sections []string, configs types.ConfigData, target any) error
Parse parses the config from config.Read into the given struct. Param target should be a pointer to the config to parse into.
func ParseStruct ¶ added in v0.1.0
ParseStruct is a helper to make any struct with `json` tags a source.Data (map[string]any{} with some more fields) with sections.
func Read ¶
Read reads urls into []Data where Data is map[string]any.
By default it will error out if any of these config URLs fail, but you can ignore errors for a single url by adding "?ignore_error=true".
prependSections is for url's that don't support sections (cli for example), their result will be prepended, also you can add sections to a single url with "?add_section=true".
func SingleGet ¶ added in v0.1.0
SingleGet returns either the value of "key" in "data" or the default value "def". If types don't match it returns ErrTypesDontMatch. If key hasn't been found it returns ErrNotExistent as well as the default value "def".
It supports the following datatypes:
- any non-container (string/float64/uvm.)
- []string slice
- []any slice
- []map[string]any
Types ¶
This section is empty.