A basic configuration loading system for Go
cfger.go | ||
go.mod | ||
go.sum | ||
LICENSE | ||
README.md | ||
types.go |
cfger
A basic configuration loading system
Install
go get git.tdpain.net/pkg/cfger
Example usage
package config
import (
"git.tdpain.net/pkg/cfger"
)
type HTTP struct {
Host string
Port int
}
type Database struct {
DSN string
}
type Config struct {
Debug bool
HTTP *HTTP
Database *Database
}
func Load() (*Config, error) {
cl := cfger.New()
if err := cl.Load("config.yml"); err != nil {
return nil, err
}
conf := &Config{
Debug: cl.Required("debug").AsBool(),
HTTP: &HTTP{
Host: cl.WithDefault("http.host", "127.0.0.1").AsString(),
Port: cl.WithDefault("http.port", 8080).AsInt(),
},
Database: &Database{
DSN: cl.WithDefault("database.dsn", "website.db").AsString(),
},
}
return conf, nil
}
License
This project is licensed under the BSD Zero Clause License. See ./LICENSE
for more information.