Created
July 10, 2014 18:39
-
-
Save Xe/126f96d97c4340c0f547 to your computer and use it in GitHub Desktop.
config parser
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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