Documentation ¶
Index ¶
Constants ¶
View Source
const DefaultKeyTagName = "key"
DefaultKeyTagName is the go annotation key name for specifying the default fieldname. The value is to be expected to use only lowercase letters and underscores, as this is deemed the best default for readability. Sources can then convert this to kebapCase, UPPER_CASE or whatever else the put their faith in.
Variables ¶
View Source
var ( // ErrExpectAtLeastOneSource indicates that no configuration can be loaded // if there's not at least one source. ErrExpectAtLeastOneSource = errors.New("please define at least one source") // ErrSourceNotFound implies that a source has been added, but for example // the file it is supposed to read can't be found. ErrSourceNotFound = errors.New("the source could not find its target") // ErrInvalidConfiguraionPointer TODO ErrInvalidConfiguraionPointer = errors.New("invalid configuration pointer passed") // ErrExportedFieldMissingKey implies that a field is exported, but // doesn't define the key required for parsing it from a source. This // error can be omitted by setting `ignore:"true"` ErrExportedFieldMissingKey = errors.New("exported field is missing key definition") // ErrValueNotSet implies that no value could be found for a field, even // though it is required. The reason is either that there's no value, no // default value or a user error has occurred (e.g. a typo in the key). ErrValueNotSet = errors.New("required not set and no non-zero default value was found") // ErrParseValue implies that the value we attempted to parse is not in // the correct format to be assigned to its corresponding field. This is // most likely a user error. ErrParseValue = errors.New("value not parsable as type specified by field") // ErrUnsupportedFieldType implies that this library does NOT YET support // a certain field type. ErrUnsupportedFieldType = errors.New("unsupported field type") )
Functions ¶
This section is empty.
Types ¶
type ParsingCompanion ¶ added in v0.0.3
type ParsingCompanion interface { // IncludeField determines whether the field should be included in parsing. // This defines the standard for YAGCL and should be used by all sources. // A source may support additional rules that may even overwrite this ruleset. IncludeField(reflect.StructField) bool // ExtractFieldKey defines which identifier should be used for the given // field. This defines the standard identifier defined by YAGCL if no // specific identifier has been found for your source. ExtractFieldKey(reflect.StructField) string }
type Source ¶
type Source interface { // Parse attempts retrieving data from the source and parsing it. This // should return true if anything was loaded. If nothing was loaded, but we // expected to load data, we should return an error. A realistic scenario // here would be that a Source is required instead of "load if found". Parse(ParsingCompanion, any) (bool, error) // KeyTag defines the golang struct field tag that defines a specific tag // for this source. This allows having one generic key, but overrides for // specific sources. KeyTag() string }
Source represents a source for configuration values. This might be backed by files of different formats, network access, environment variables or even the Windows registry. While YAGCL offers default sources, you can easily integrate your own source.
type YAGCL ¶
type YAGCL[T any] interface { // Add adds a single source to read configuration from. This method can // be called multiple times, adding multiple ordered sources. Whatever is // added first is preferred. If AllowOverride() is called, all source will be // parsed in the defined order. Add(source Source) YAGCL[T] // AllowOverride allows YAGCL to read from multiple sources. For example more // than one JSON file or a JSON file and the environment. AllowOverride() YAGCL[T] // InferFieldKeys activates automtic generation of a field key if none has // been defined by the programmers. InferFieldKeys() YAGCL[T] // AdditionalKeyTags defines tags other than `key`, which will then be used // by ParsingCompanion.ExtractFieldKey. AdditionalKeyTags(tags ...string) YAGCL[T] // Parse expects a pointer to a struct, which it'll attempt loading the // configuration into. Note that you'll first have to specify any type // type of configuration to be loaded. Parse(configurationStruct *T) error }
YAGCL defines the setup interface for YAGCL.
Click to show internal directories.
Click to hide internal directories.