Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/myomikron/goconfig
Go implementation of staticconfig
https://github.com/myomikron/goconfig
Last synced: 19 days ago
JSON representation
Go implementation of staticconfig
- Host: GitHub
- URL: https://github.com/myomikron/goconfig
- Owner: myOmikron
- License: gpl-2.0
- Created: 2022-03-12T00:07:34.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2022-03-12T00:50:57.000Z (over 2 years ago)
- Last Synced: 2024-06-21T06:27:35.082Z (5 months ago)
- Language: Go
- Size: 10.7 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# goconfig
## Usage
```go
package mainimport (
"fmt"
"github.com/myOmikron/goconfig"
)type Database struct {
Host string `json:"host"`
Port int `json:"port"`
User string `json:"user"`
Password string `json:"password"`
}type MyConfig struct {
Uri string `json:"uri"` // String
Count int `json:"count"` // Int
Servers []interface{} `json:"servers"` // Generic list
DB Database `json:"db"` // Nested Object
}func main() {
// Use empty config without defaults
conf := MyConfig{}// or set some defaults
conf = MyConfig{
Servers: []interface{}{
"127.0.0.1",
"localhost",
},
DB: Database{Port: 3306},
}// Create / Parse config file
goconfig.ParseConfig("config.json", &conf)fmt.Printf("Current configuration: %#v\n", conf)
}```