forked from Ayin-a/hkrpg-go
-
Notifications
You must be signed in to change notification settings - Fork 3
/
config.go
135 lines (127 loc) · 3.1 KB
/
config.go
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
package config
import (
"encoding/json"
"errors"
"os"
"github.com/Eichs/hkrpg-go/pkg/random"
)
type Config struct {
LogLevel string `json:"LogLevel"`
GameDataConfigPath string `toml:"GameDataConfigPath"`
MysqlDsn string `json:"MysqlDsn"`
Account *Account `json:"Account"`
Http *Http `json:"Http"`
Https *Https `json:"Https"`
Dispatch []Dispatch `json:"Dispatch"`
Game *Game `json:"Game"`
GmKey string `json:"GmKey"`
Email *email `json:"Email"`
Ec2b *random.Ec2b `json:"Ec2B"`
}
type Account struct {
AutoCreate bool `json:"autoCreate"`
MaxPlayer int32 `json:"maxPlayer"`
}
type Dispatch struct {
Name string `json:"name"`
Title string `json:"title"`
Type string `json:"type"`
DispatchUrl string `json:"dispatchUrl"`
}
type Http struct {
Addr string `json:"addr"`
Port int64 `json:"port"`
}
type Https struct {
Enable bool `json:"enable"` // 是否启动 HTTPS
Addr string `json:"addr"` // HTTPS 服务地址
Port int64 `json:"port"` // HTTPS 服务端口
CertFile string `json:"certFile"` // 证书文件路径
KeyFile string `json:"keyFile"` // 密钥文件路径
}
type Game struct {
Addr string `json:"addr"`
Port uint32 `json:"port"`
}
type email struct {
From string `json:"from"`
Addr string `json:"addr"`
Host string `json:"host"`
Identity string `json:"identity"`
}
var CONF *Config = nil
func GetConfig() *Config {
return CONF
}
var FileNotExist = errors.New("config file not found")
func LoadConfig() error {
filePath := "./config.json"
if len(os.Args) > 1 {
filePath = os.Args[1]
}
f, err := os.Open(filePath)
if err != nil {
return FileNotExist
}
defer func() {
_ = f.Close()
}()
c := new(Config)
d := json.NewDecoder(f)
if err := d.Decode(c); err != nil {
return err
}
CONF = c
return nil
}
var DefaultConfig = &Config{
LogLevel: "Info",
GameDataConfigPath: "resources",
MysqlDsn: "root:password@tcp(127.0.0.1:3306)/hkrpg-go?charset=utf8mb4&parseTime=True&loc=Local",
Account: &Account{
AutoCreate: true,
MaxPlayer: -1,
},
Http: &Http{
Addr: "0.0.0.0",
Port: 8080,
},
Https: &Https{
Enable: true,
Addr: "0.0.0.0",
Port: 8443,
CertFile: "data/localhost.crt",
KeyFile: "data/localhost.key",
},
Dispatch: []Dispatch{
{
Name: "hkrpg-go",
Title: "os_usa",
Type: "2",
DispatchUrl: "http://127.0.0.1:8080/query_gateway",
},
{
Name: "hkrpg-official-os",
Title: "OS客户端更新",
Type: "2",
DispatchUrl: "http://127.0.0.1:8080/query_gateway_capture_os",
},
{
Name: "hkrpg-official-cn",
Title: "CN客户端更新",
Type: "2",
DispatchUrl: "http://127.0.0.1:8080/query_gateway_capture_cn",
},
},
Game: &Game{
Addr: "127.0.0.1",
Port: 22102,
},
GmKey: "",
Email: &email{
From: "123456789@qq.com",
Addr: "smtp.qq.com:587",
Host: "smtp.qq.com",
Identity: "123456789",
},
}