confjson

package module
v0.0.0-...-fc25809 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 8, 2019 License: GPL-3.0 Imports: 4 Imported by: 1

README

confJSON

CircleCI

Simple GO implementatin for storage application configuration as map[string]interface{} in JSON file.

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

func Load(file string) (map[string]interface{}, error)

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

func Save(file string, cfg map[string]interface{}) error

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL