config

package module
v0.0.0-...-770bc48 Latest Latest
Warning

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

Go to latest
Published: Jan 1, 2019 License: AGPL-3.0 Imports: 7 Imported by: 6

README

This is a Go package which helps with reading configuration files.

Documentation

Overview

Package config is a config file parser.

A note on usage: Due to the fact that we use the reflect package, you must pass in the struct for which you want to parse config keys using all exported fields, or this config package cannot set those fields.

Key names are case insensitive.

For an example of using this package, see the test(s).

For the types that we support parsing out of the struct, refer to the populateConfig() function.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetConfig

func GetConfig(path string, config interface{}) error

GetConfig reads a config file and populates a struct with what is read.

We use the reflect package to populate the struct from the config.

Currently every member of the struct must have had a value set in the config. That is, every config option is required.

func PopulateStruct

func PopulateStruct(config interface{}, rawValues map[string]string) error

PopulateStruct takes values read from a config as a string map, and uses them to populate a struct. The values will be converted to the struct's types as necessary.

To understand the use of reflect in this function, refer to the article Laws of Reflection, or the documentation of the reflect package.

func ReadStringMap

func ReadStringMap(path string) (map[string]string, error)

ReadStringMap a config file and returns the keys and values in a map where keys and values are strings.

The config file syntax is: key = value

Lines may be commented if they begin with a '#' with only whitespace or no whitespace in front of the '#' character. Lines currently MAY NOT have trailing '#' to be treated as comments.

Types

This section is empty.

Jump to

Keyboard shortcuts

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