https://github.com/tfcloud-go/config
Go package for config. Inspired by OpenStack oslo.config library.
https://github.com/tfcloud-go/config
configuration go ini-config openstack oslo tfcloud
Last synced: 5 months ago
JSON representation
Go package for config. Inspired by OpenStack oslo.config library.
- Host: GitHub
- URL: https://github.com/tfcloud-go/config
- Owner: tfcloud-go
- License: apache-2.0
- Created: 2021-05-20T14:13:06.000Z (about 5 years ago)
- Default Branch: main
- Last Pushed: 2023-06-20T01:20:55.000Z (almost 3 years ago)
- Last Synced: 2025-01-23T21:16:21.809Z (over 1 year ago)
- Topics: configuration, go, ini-config, openstack, oslo, tfcloud
- Language: Go
- Homepage:
- Size: 15.6 KB
- Stars: 1
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# TFCloud Go Config
Go package for config. Inspired by OpenStack [oslo.config](https://opendev.org/openstack/oslo.config) library.
## Usage
Install package
```shell
go get github.com/tfcloud-go/config
```
Register configurations
```go
// conf/server.go
package conf
// ...
var CONF = config.CONF
func init() {
group := config.NewOptGroup("server")
CONF.RegisterGroup(group)
host := config.NewStrOpt("host").WithDefault("127.0.0.1")
port := config.NewIntOpt("port").WithDefault(8080)
CONF.RegisterOpts(group, host, port)
}
```
Parse configurations
```go
// main.go
package main
// ...
var CONF = config.CONF
func main() {
// ...
CONF.ParseFile("your_config_file_name.conf")
// ...
}
```
Get configuration value
```go
// foo/server.go
package foo
// ...
var CONF = config.CONF
func startServer() {
host := CONF.GetString("server", "host")
port, _ := CONF.GetInt("server", "port")
addr := net.JoinHostPort(host, port)
// ...
}
```
Use configuration file
```shell
foo-server --config your_config_file_name.conf
```
## Copyright
The TFCloud Go Team. [Apache License 2.0](./LICENSE)