https://github.com/choueric/jconfig
Simple JSON configuration file tools.
https://github.com/choueric/jconfig
golang json
Last synced: about 1 month ago
JSON representation
Simple JSON configuration file tools.
- Host: GitHub
- URL: https://github.com/choueric/jconfig
- Owner: choueric
- License: gpl-3.0
- Created: 2017-01-10T02:00:25.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2020-03-11T03:18:41.000Z (over 6 years ago)
- Last Synced: 2025-10-09T16:19:50.267Z (9 months ago)
- Topics: golang, json
- Language: Go
- Size: 21.5 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# jconfig
This is a Go package to parse a configuration file using JSON.
[](https://travis-ci.org/choueric/jconfig)
[](https://godoc.org/github.com/choueric/jconfig)
## Installation
```sh
go get github.com/choueric/jconfig
import (
"github.com/choueric/jconfig"
)
```
## Usage
-----
```go
package main
import (
"fmt"
"github.com/choueric/jconfig"
)
const DefContent = `{
"server": "127.0.0.1:8088"
}
`
type Config struct {
Server string `json:"server"`
}
func getConfig() *Config {
// NOTE: Config{} is the your own type to store configurations.
jc := jconfig.New("config.json", Config{})
if _, err := jc.Load(DefContent); err != nil {
fmt.Println("load config error:", err)
return nil
}
return jc.Data().(*Config) // convert to your own type and return.
}
```
Refer to `jconfig_test.go` for more details of how to use it.
Another usage is config.go of [kbdashboard](https://github.com/choueric/kernelBuildDashboard.git)