https://github.com/deepch/config
json config
https://github.com/deepch/config
config go golang json
Last synced: about 2 months ago
JSON representation
json config
- Host: GitHub
- URL: https://github.com/deepch/config
- Owner: deepch
- Created: 2017-04-23T01:24:42.000Z (about 9 years ago)
- Default Branch: master
- Last Pushed: 2017-09-10T18:17:39.000Z (almost 9 years ago)
- Last Synced: 2025-07-21T21:53:53.259Z (12 months ago)
- Topics: config, go, golang, json
- Language: Go
- Homepage:
- Size: 3.91 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
## JSON config parser and encoder for Go
Installation:
```bash
go get github.com/deepch/config
```
### Examples
This package works `JSON`.
For the simplest example, consider some JSON file as just a list of keys
and values:
```json
{
"Age": 25,
"Cats": [
"Cauchy",
"Plato"
],
"Pi": 3.14,
"Perfection": [
6,
28,
496,
8128
],
"DOB": "1987-07-05T05:45:00.000Z"
}
```
Which could be defined in Go as:
```go
type Config struct {
Age int
Cats []string
Pi float64
Perfection []int
DOB time.Time // requires `import time`
}
```
And then decoded with:
```go
var conf Config
if _, err := config.Decode(jsonFileString, &conf); err != nil {
// handle error
}
```
And then encode with:
```go
if _, err := config.Encode(jsonFileString, &conf); err != nil {
// handle error
}
```
You can also use struct tags if your struct field name doesn't map to a JSON
key value directly:
```json
some_key_NAME = "wat"
```
```go
type json struct {
ObscureKey string `json:"some_key_NAME"`
}
```
You can use omitempty
```go
type json struct {
ObscureKey string `json:"some_key_NAME,omitempty"`
}
```
If use omitempty and Encode not save zero 0 (defoult) data
You can line and char error
```bash
Decode Config Syntax Error File config/file.conf
Line 5 Char 1 Error invalid character '1' looking for beginning of object key string
```