This commit is contained in:
zhouyuyan
2017-08-25 15:28:41 +08:00
parent 0bc226d071
commit 0ea7da1dc0
8 changed files with 91 additions and 25 deletions

42
broker/config.go Normal file
View File

@@ -0,0 +1,42 @@
package broker
import (
"encoding/json"
"errors"
"io/ioutil"
"github.com/prometheus/common/log"
)
const (
CONFIGFILE = "broker.config"
)
type Config struct {
Host string `json:"host"`
Port string `json:"port"`
}
func LoadConfig() (*Config, error) {
content, err := ioutil.ReadFile(CONFIGFILE)
if err != nil {
log.Error("Read config file error: ", err)
return nil, err
}
var info Config
err = json.Unmarshal(content, &info)
if err != nil {
log.Error("Unmarshal config file error: ", err)
return nil, err
}
if info.Port != "" {
if info.Host == "" {
info.Host = "0.0.0.0"
}
} else {
return nil, errors.New("Listen port nil")
}
return &info, nil
}