mirror of
https://github.com/crazy-max/diun.git
synced 2025-12-24 06:28:13 +01:00
Configuration file not required anymore DIUN_DB env var renamed DIUN_DB_PATH Only accept duration as timeout value (10 becomes 10s) Add getting started doc Enhanced documentation Add note about test notifications (#79) Improve configuration management Fix telegram init All fields in configuration now camelCased Improve configuration validation Update doc Update FAQ Co-authored-by: CrazyMax <crazy-max@users.noreply.github.com>
33 lines
962 B
Go
33 lines
962 B
Go
// Package file implements decoding between configuration in a file and a typed Configuration.
|
|
package file
|
|
|
|
import (
|
|
"github.com/crazy-max/diun/v3/third_party/traefik/config/parser"
|
|
)
|
|
|
|
// Decode decodes the given configuration file into the given element.
|
|
// The operation goes through three stages roughly summarized as:
|
|
// file contents -> tree of untyped nodes
|
|
// untyped nodes -> nodes augmented with metadata such as kind (inferred from element)
|
|
// "typed" nodes -> typed element
|
|
func Decode(filePath string, element interface{}) error {
|
|
if element == nil {
|
|
return nil
|
|
}
|
|
|
|
filters := getRootFieldNames(element)
|
|
|
|
root, err := decodeFileToNode(filePath, filters...)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
metaOpts := parser.MetadataOpts{TagName: parser.TagLabel, AllowSliceAsStruct: true}
|
|
err = parser.AddMetadata(element, root, metaOpts)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
return parser.Fill(element, root, parser.FillerOpts{AllowSliceAsStruct: true})
|
|
}
|