utils

package
v1.0.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 28, 2022 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ArgsMapToObject added in v1.0.0

func ArgsMapToObject(args map[string]string, obj interface{}) error

ArgsMapToObject converts a string map to an object via JSON encode/decode

func ClearString added in v1.0.0

func ClearString(str string) string

func GetDefaultPath

func GetDefaultPath(productname string) string

func GetSectionsMap added in v0.9.1

func GetSectionsMap(jsonBytes []byte) (map[string]interface{}, error)

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 ReadBytesFromFile(filePath string, configFileDir string) []byte

func ReadBytesFromUrl added in v0.9.1

func ReadBytesFromUrl(url string) []byte

func ReadObjectFromURL added in v1.0.0

func ReadObjectFromURL(url string, obj interface{}) error

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

func URLArgsToJSON(args map[string][]string) []byte

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

func URLArgsToMap(args map[string][]string) map[string]string

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

func WriteSection added in v0.9.1

func WriteSection(jsonBytes []byte, sectionName string, configStruct interface{}) ([]byte, error)

WriteSection puts the ConfigStruct object in the config file by preserving everything that is part of the section

Types

type ConfigIncluder

type ConfigIncluder struct {
	Include        string
	IncludeFromURL string
}

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

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL