Documentation
¶
Overview ¶
Package config provides config handling for go-micro.
Index ¶
- Variables
- func Dump(codecMime string, config map[string]any) ([]byte, error)
- func HasKey[T any](sections []string, key string, config map[string]any) bool
- func Merge[T any](dst *T, src T) error
- func Parse[TMap any](sections []string, key string, config map[string]any, target TMap) error
- func ParseSlice[TSlice any](sections []string, key string, config map[string]any, target TSlice) error
- func ParseStruct[TParse any](sections []string, toParse TParse) (map[string]any, error)
- func Read(url *url.URL) (map[string]any, error)
- func SingleGet[T any](data map[string]any, key string, def T) (T, error)
- func WalkMap(sections []string, in map[string]any) (map[string]any, error)
- type Duration
- type URL
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?") // ErrNoSuchKey happens when a config key is not existent. ErrNoSuchKey = 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 HasKey ¶ added in v0.1.0
HasKey returns a boolean which indidcates if the given sections and key exists in the configs.
func Parse ¶
Parse parses the config from config.Read into the given struct. Param target should be a pointer to the config to parse into.
func ParseSlice ¶ added in v0.3.0
func ParseSlice[TSlice any](sections []string, key string, config map[string]any, target TSlice) error
ParseSlice parses the config from config.Read into the given slice. Param target should be a pointer to the slice to parse into.
func ParseStruct ¶ added in v0.1.0
ParseStruct is a helper to make any struct with `json` tags a map[string]any with sections.
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
func WalkMap ¶ added in v0.3.0
WalkMap walks into the sections and returns the map[string]any of that section.
If a section is a slice, the next section should be a number.
Example:
config := map[string]any{
"foo": map[string]any{
"bar": map[string]any{
"baz": "value",
},
},
}
WalkMap([]string{"foo", "bar"}, config) returns map[string]any{"baz": "value"}.
Types ¶
type Duration ¶ added in v0.3.0
Duration is a time.Duration that can be parsed from a string or float64. https://stackoverflow.com/a/54571600
func (Duration) MarshalJSON ¶ added in v0.3.0
MarshalJSON implements the json.Marshaler interface.
func (*Duration) UnmarshalJSON ¶ added in v0.3.0
UnmarshalJSON implements the json.Unmarshaler interface.
type URL ¶ added in v0.3.0
URL represents a URL in JSON.
func (*URL) MarshalJSON ¶ added in v0.3.0
MarshalJSON marshals the JURL to JSON.
func (*URL) UnmarshalJSON ¶ added in v0.3.0
UnmarshalJSON unmarshals the JURL from JSON.