package conf import ( "encoding/xml" "io/ioutil" _ "strings" "common/logger" ) type RedisConf struct { Host string `xml:",attr"` Db uint32 `xml:",attr"` Password string `xml:",attr"` } type ConiSrvConf struct { Host string `xml:",attr"` Key string `xml:",attr"` } type TexasConf struct { ServerHttpAddr ServerHttpAddrConf `xml:"ServerHttpAddr"` Redis RedisConf `xml:"Redis"` CoinSrv ConiSrvConf `xml:"CoinSrv"` } var ( config = new(TexasConf) ) func GetRedisConf() RedisConf { return config.Redis } func LoadConf(filename string) error { content, err := ioutil.ReadFile(filename) if err != nil { logger.Notic("read file:%v error:", filename, err) return err } logger.Info("conf xml:%v", string(content)) err = xml.Unmarshal(content, config) if err != nil { logger.Notic("decode xml error:%v", err) return err } DumpConf() return nil } func DumpConf() { logger.Info("--------------config dump----start--------") logger.Info("conf=%+v", config) logger.Info("--------------config dump----end--------") } func GetServerHttpAddrConf() string { return config.ServerHttpAddr.Host } type ServerHttpAddrConf struct { Host string `xml:",attr"` }