Documentation ¶
Index ¶
- func ArgsMapToObject(args map[string]string, obj interface{}) error
- func ClearString(str string) string
- func GetDefaultPath(productname string) string
- func GetSectionsMap(jsonBytes []byte) (map[string]interface{}, error)
- func ReadBytesFromFile(filePath string, configFileDir string) []byte
- func ReadBytesFromUrl(url string) []byte
- func ReadObjectFromURL(url string, obj interface{}) error
- func ReadSectionWithDefaults(jsonBytes []byte, sectionName string, configStruct interface{}, ...) ([]byte, error)
- func URLArgsToJSON(args map[string][]string) []byte
- func URLArgsToMap(args map[string][]string) map[string]string
- func WriteSection(jsonBytes []byte, sectionName string, configStruct interface{}) ([]byte, error)
- type ConfigIncluder
- type ConfigReader
- func (c *ConfigReader) GetConfigDir() string
- func (c *ConfigReader) GetConfigFileContent() string
- func (c *ConfigReader) GetSectionBytes(sectionName string) ([]byte, error)
- func (c *ConfigReader) GetSectionNames() ([]string, error)
- func (c *ConfigReader) ReadObjectFromFile(obj interface{}, filename string) error
- func (c *ConfigReader) ReadObjectFromURL(obj interface{}, url string) error
- func (c *ConfigReader) ReadSectionWithDefaults(sectionName string, configStruct interface{}) error
- func (c *ConfigReader) SetConfigFileContent(newContent string) error
- func (c *ConfigReader) WriteBackConfigIfChanged() error
- func (c *ConfigReader) WriteObjectToFile(obj interface{}, filename string) error
- func (c *ConfigReader) WriteSection(sectionName string, configStruct interface{}, persistImmediately bool) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ArgsMapToObject ¶ added in v1.0.0
ArgsMapToObject converts a string map to an object via JSON encode/decode
func ClearString ¶ added in v1.0.0
func GetDefaultPath ¶
func GetSectionsMap ¶ added in v0.9.1
GetSectionsMap returns a map of section names to config-objects, the type of config-object depends on the section
func ReadBytesFromFile ¶ added in v0.9.1
func ReadBytesFromUrl ¶ added in v0.9.1
func ReadObjectFromURL ¶ added in v1.0.0
ReadObjectFromURL decodes a JSON object from an http stream
func ReadSectionWithDefaults ¶
func ReadSectionWithDefaults(jsonBytes []byte, sectionName string, configStruct interface{}, configFileDir string) ([]byte, error)
ReadSectionWithDefaults parses the content of the first-level-JSON object in <sectionName> into configStruct
if the section exists, configStruct will first get overwritten by an optional included file, then by the contents of the section (append+overwrite in both cases), returns an empty byte-slice if the section does not exist, the serialized content of configStruct (assuming these are default values) is added to jsonBytes and returned
func URLArgsToJSON ¶
URLArgsToJSON converts the string map of arrays to a string map of strings by dropping all but the first elements from the map, it returns the json serialization of the map
func URLArgsToMap ¶ added in v1.0.0
URLArgsToMap converts the string map of arrays to a string map of strings by dropping all but the first elements from the map, it returns the resulting map
Types ¶
type ConfigIncluder ¶
type ConfigReader ¶
type ConfigReader struct {
// contains filtered or unexported fields
}
func NewConfigReader ¶
func NewConfigReader(logger logrus.FieldLogger, configFilePath string) (*ConfigReader, error)
func (*ConfigReader) GetConfigDir ¶ added in v1.0.0
func (c *ConfigReader) GetConfigDir() string
GetConfigDir returns the basepath of the config file
func (*ConfigReader) GetConfigFileContent ¶ added in v1.0.0
func (c *ConfigReader) GetConfigFileContent() string
GetConfigFileContent returns the content of the config file
func (*ConfigReader) GetSectionBytes ¶ added in v0.9.1
func (c *ConfigReader) GetSectionBytes(sectionName string) ([]byte, error)
GetSectionBytes returns the bytes of the section given by sectionName
func (*ConfigReader) GetSectionNames ¶ added in v0.9.1
func (c *ConfigReader) GetSectionNames() ([]string, error)
GetSectionNames returns the names of all sections in the config file
func (*ConfigReader) ReadObjectFromFile ¶ added in v1.0.0
func (c *ConfigReader) ReadObjectFromFile(obj interface{}, filename string) error
func (*ConfigReader) ReadObjectFromURL ¶ added in v1.0.0
func (c *ConfigReader) ReadObjectFromURL(obj interface{}, url string) error
func (*ConfigReader) ReadSectionWithDefaults ¶
func (c *ConfigReader) ReadSectionWithDefaults(sectionName string, configStruct interface{}) error
func (*ConfigReader) SetConfigFileContent ¶ added in v1.0.0
func (c *ConfigReader) SetConfigFileContent(newContent string) error
SetConfigFileContent validates the new Content and sets it if valid
func (*ConfigReader) WriteBackConfigIfChanged ¶
func (c *ConfigReader) WriteBackConfigIfChanged() error
func (*ConfigReader) WriteObjectToFile ¶ added in v1.0.0
func (c *ConfigReader) WriteObjectToFile(obj interface{}, filename string) error
func (*ConfigReader) WriteSection ¶ added in v0.9.1
func (c *ConfigReader) WriteSection(sectionName string, configStruct interface{}, persistImmediately bool) error