conf.go 1.38 KB
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 TexasConf struct {
	GameDB                  MysqlConf           `xml:"GameDB"`
	ServerHttpAddr ServerHttpAddrConf `xml:"ServerHttpAddr"`
	Redis          RedisConf          `xml:"Redis"`
}

var (
	config = new(TexasConf)
)

func GetRedisConf() RedisConf {
	return config.Redis
}
type MysqlConf struct {
	Ip           string `xml:",attr"`
	Port         int    `xml:",attr"`
	User         string `xml:",attr"`
	Pwd          string `xml:",attr"`
	Database     string `xml:",attr"`
	LoadInterval int    `xml:",attr"`
}

func GetGameDBConf() MysqlConf {
	return config.GameDB
}

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("--------------config dump----end--------")
}

func GetServerHttpAddrConf() string {
	return config.ServerHttpAddr.Host
}

type ServerHttpAddrConf struct {
	Host string `xml:",attr"`
}