Skip to content

RestartFU/gophig

Gophig

Gophig is a simple configuration manager for Go projects. It supports marshaling and unmarshaling config files (e.g., TOML) into typed Go structs.

Installation

go get git.restartfu.com/restart/gophig

Usage

Define your configuration struct:

type Foo struct {
	Foo string toml:"foo"
	Bar string toml:"bar"
}

Create a new *Gophig instance:

g := gophig.NewGophig[Foo]("./config.toml", gophig.TOMLMarshaler, os.ModePerm)

Writing a Config

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"

Reading a Config

myFoo, err := g.ReadConf()
if err != nil {
  log.Fatalln(err)
}

log.Println(myFoo)

Output:

{Foo: "foo", Bar: "bar"}

About

library to easily write or read configs, supports json, toml and yaml

Topics

Resources

License

Code of conduct

Contributing

Stars

Watchers

Forks

Packages

No packages published

Contributors 2

  •  
  •