Gophig is a simple configuration manager for Go projects. It supports marshaling and unmarshaling config files (e.g., TOML) into typed Go structs.
go get git.restartfu.com/restart/gophig
Define your configuration struct:
type Foo struct {
Foo string toml:"foo"
Bar string toml:"bar"
}g := gophig.NewGophig[Foo]("./config.toml", gophig.TOMLMarshaler, os.ModePerm)myFoo := Foo{Foo: "foo", Bar: "bar"}
if err := g.WriteConf(myFoo); err != nil {
log.Fatalln(err)
}This will generate a config.toml file with:
foo = "foo"
bar = "bar"
myFoo, err := g.ReadConf()
if err != nil {
log.Fatalln(err)
}
log.Println(myFoo)Output:
{Foo: "foo", Bar: "bar"}