Blame view

conf/conf.go 1.59 KB
ee23102d   zhangqijia   支持mongo, grpc接服务器
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
  package conf
  
  import (
  	"fmt"
  	lumberjack "gopkg.in/natefinch/lumberjack.v2"
  	"gopkg.in/yaml.v3"
  	"io/ioutil"
  	"pro2d/utils"
  )
  
  type RedisConf struct {
  	Address string `json:"address"`
  	Auth 	string `json:"auth"`
  	DB 		int 		`json:"db"`
  }
  
  type EndPoint struct {
  	Address string `json:"address"`
  }
  
  type Etcd struct {
  	Endpoints []EndPoint `json:"endpoints"`
  }
  
  type MongoConf struct {
  	User 		string		`yaml:"user"`
  	Password 	string		`yaml:"password"`
  	Host  		string		`yaml:"host"`
  	Port 		int			`yaml:"port"`
  	DBName  	string		`yaml:"dbname"`
  	TimeOut  	int			`yaml:"timeout"`
  	MaxNum  	int			`yaml:"maxnum"`
  }
  
  type SConf struct {
  	Name string `yaml:"name"`
  	IP   string `yaml:"ip"`
  	Port int 	`yaml:"port"`
  	MongoConf   *MongoConf	`yaml:"mongo"`
  }
  
  type ServerConf struct {
  	ID 				string 		`yaml:"id"`
  	Name 			string 		`yaml:"name"`
  	WorkerID    	int64		`yaml:"workerid"`
  	DatacenterID 	int64		`yaml:"datacenterid"`
  	AccountConf 	*SConf 		`yaml:"server_account"`
  	GameConf		*SConf 		`yaml:"server_game"`
  	RedisConf   	*RedisConf  `yaml:"redis"`
  	LogConf  		*lumberjack.Logger `json:"logconf"`
  	Etcd 			*Etcd 		`yaml:"etcd"`
  }
  
  var GlobalConf ServerConf
  var SnowFlack *utils.Snowflake
  func init() {
  	configFile, err := ioutil.ReadFile("conf/conf.yaml")
  	if err != nil {
  		fmt.Printf("conf faild: %v", err)
  		return
  	}
  	//初始化配置
  	if err = yaml.Unmarshal(configFile, &GlobalConf); err != nil {
  		fmt.Printf("yaml unmarshal faild: %v", err)
  		return
  	}
  
  	//初始化日志
  	utils.InitLogger(GlobalConf.LogConf)
  
  	//初始化雪花算法
  	SnowFlack = utils.NewSnowflake(GlobalConf.WorkerID, GlobalConf.DatacenterID)
  }