Configo
Dead Simple Config Management, load and persist config without having to think about where and how.
Install
go get github.com/UltiRequiem/configo
Usage
package main
import (
"fmt"
"log"
"github.com/UltiRequiem/configo"
)
func main() {
config, err := configo.NewConfig("example")
if err != nil {
log.Fatal(err)
}
// Only if you want to persist values
defer config.Save()
config.Set("awesome", 777)
fmt.Println(config.Get("awesome")) //=> 777
fmt.Println(config.Has("awesome")) //=> true
config.Delete("awesome")
fmt.Println(config.Get("awesome")) //=> nil
fmt.Println(config.Size()) //=> 0
config.Set("foo", "bar")
fmt.Println(config.Size()) //=> 1
}
If you already ran the code snippet from before, then this will work:
package main
import (
"fmt"
"log"
"github.com/UltiRequiem/configo"
)
func main() {
config, err := configo.NewConfig("example")
if err != nil {
log.Fatal(err)
}
fmt.Println(config.Get("foo")) // "bar"
}
API
NewConfig
Returns a new instance of Configo
.
Configo.Get
Returns the value
on the key
passed.
Configo.GetAll
Returns a map with all the config.
Configo.Set
Set the value
in the key
passed.
Configo.SetAll
Receives a map[string]interface{}
.
Configo.Has
It tells you if it has the received key
.
Configo.Delete
Deletes the key
passed.
Configo.Size
Returns the quantity of the config properties.
Configo.Clear
Removes all the values of the config.
Configo.Path
Gives you the path were the config is stored.
Configo.Save
Saves the config for persistence.
Licence
This project is licensed under the MIT Licence.