Skip to content

Instantly share code, notes, and snippets.

@Xe
Created July 10, 2014 18:39
Show Gist options
  • Save Xe/126f96d97c4340c0f547 to your computer and use it in GitHub Desktop.
Save Xe/126f96d97c4340c0f547 to your computer and use it in GitHub Desktop.
config parser
package tetra
import (
"encoding/json"
"io/ioutil"
)
type ServerConfig struct {
Name string `json:"name"`
Gecos string `json:"gecos"`
Sid string `json:"sid"`
}
type ServiceConfig struct {
Nick string `json:"nick"`
User string `json:"user"`
Host string `json:"host"`
Gecos string `json:"gecos"`
Name string `json:"name"`
}
type UplinkConfig struct {
Host string `json:"host"`
Port string `json:"port"`
Password string `json:"password"`
Ssl bool `json:"ssl"`
}
type Config struct {
Autoload []string `json:"autoload"`
Services []*ServiceConfig `json:"services"`
Server *ServerConfig `json:"myinfo"`
Uplink *UplinkConfig `json:"uplink"`
RRDPath string `json:"rrdpath"`
}
func NewConfig(fname string) (conf *Config) {
contents, err := ioutil.ReadFile(fname)
if err != nil {
panic(err)
}
json.Unmarshal(contents, conf)
return
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment