Skip to content

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

License

Notifications You must be signed in to change notification settings

RestartFU/gophig

Repository files navigation

Mirror:

⚠️ This is a mirror of this repository

Getting Started

Gophig may be imported using go get:

go get git.restartfu.com/restart/gophig.git

Usage

You may create a new *Gophig:

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

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

Then you may use the method WriteConf(v any):

myFooStruct := Foo{foo: "foo", bar: "bar"}

if err := g.SaveConf(myFooStruct);err != nil{
   log.Fatalln(err)
}

// Output file content:
// ./config.toml
/* 
   foo = "foo"
   bar = "bar"
*/

Or the method ReadConf[T any]() T:

// If we assume that the output file content is the same as the example up there:
myFooStruct, err := g.LoadConf(&myFooStruct)
if err != nil {
log.Fatalln(err)
}

log.Println(foo)

// Output:
/*
   {foo: "foo", bar: "bar"}
*/

About

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

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published