Documentation
¶
Overview ¶
Package confjson - is a simple tool to read/store configuration in the JSON format file. Values stored as empty interface. So, to use values yo have to convert them to required format.
Note that saved int value will be read as float64!
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Load ¶
Load reads JSON file in to cfg map.
Example ¶
readCfg, err := Load(fileName)
if err != nil {
log.Fatal(err)
}
for k, v := range readCfg {
fmt.Printf("%s: %#v\n", k, v)
}
Output: key1: "value1" key2: 42 key3: true
func Save ¶
Save stores configuration map in to JSON-formatted file.
Example ¶
conf := map[string]interface{}{
"key1": "value1",
"key2": 42,
"key3": true,
}
err := Save(fileName, conf)
if err != nil {
log.Fatal(err)
}
// read the file
file, err := os.Open(fileName)
if err != nil {
log.Fatal(err)
}
data := make([]byte, 100)
l, err := file.Read(data)
if err != nil {
log.Fatal(err)
}
// remove "{" and "}"
s := string(data[1 : l-1])
s = strings.Replace(s, ",", "\n", -1)
fmt.Println(s)
Output: "key1":"value1" "key2":42 "key3":true
Types ¶
This section is empty.
Click to show internal directories.
Click to hide internal directories.