Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/wiggin77/cfg
Golang package for app configuration.
https://github.com/wiggin77/cfg
configuration go
Last synced: 4 months ago
JSON representation
Golang package for app configuration.
- Host: GitHub
- URL: https://github.com/wiggin77/cfg
- Owner: wiggin77
- License: mit
- Created: 2018-07-14T00:45:11.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2024-01-18T22:56:36.000Z (about 1 year ago)
- Last Synced: 2024-06-20T21:27:31.128Z (8 months ago)
- Topics: configuration, go
- Language: Go
- Size: 51.8 KB
- Stars: 1
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# cfg
[![GoDoc](https://godoc.org/github.com/wiggin77/cfg?status.svg)](https://godoc.org/github.com/wiggin77/cfg)
![Build Status](https://github.com/wiggin77/cfg/actions/workflows/go.yml/badge.svg)Go package for app configuration. Supports chained configuration sources for multiple levels of defaults.
Includes APIs for loading Linux style configuration files (name/value pairs) or INI files, map based properties,
or easily create new configuration sources (e.g. load from database).Supports monitoring configuration sources for changes, hot loading properties, and notifying listeners of changes.
## Usage
```Go
config := &cfg.Config{}
defer config.Shutdown() // stops monitoring// load file via filespec string, os.File
src, err := cfg.NewSrcFileFromFilespec("./myfile.conf")
if err != nil {
return err
}
// add src to top of chain, meaning first searched
config.PrependSource(src)// fetch prop 'retries', default to 3 if not found
val := config.Int("retries", 3)
```See [example](./example_test.go) for more complete example, including listening for configuration changes.
Config API parses the following data types:
| type | method | example property values |
| ------- | ------ | -------- |
| string | Config.String | test, "" |
| int | Config.Int | -1, 77, 0 |
| int64 | Config.Int64 | -9223372036854775, 372036854775808 |
| float64 | Config.Float64 | -77.3456, 95642331.1 |
| bool | Config.Bool | T,t,true,True,1,0,False,false,f,F |
| time.Duration | Config.Duration | "10ms", "2 hours", "5 min" * |\* Units of measure supported: ms, sec, min, hour, day, week, year.