pet_home_server/src/server/conf/json.go
2025-12-01 15:17:07 +08:00

85 lines
1.5 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package conf
import (
"encoding/json"
"io"
"os"
"server/pkg/github.com/name5566/leaf/log"
)
var Server struct {
AppID int
AppPath string
LogLevel string
LogPath string
WSAddr string
CertFile string
KeyFile string
TCPAddr string
MaxConnNum int
ConsolePort int
ProfilePath string
MySqlAddr string
MySqlUsr string
MySqlPort string
MySqlPwd string
DbName string
RedisAddr string
RedisPort string
RedisPwd string
RedisDb int
RedisWriteAddr string // 主写地址host:port 或 单独 host, 仍兼容旧 RedisAddr/RedisPort
RedisReadAddrs string // 只读地址逗号分隔host:port,...
RedisMasterName string // 哨兵模式下的 master 名称
RedisConnType string // "Direct" 或 "Sentinel"
GameName string
ServerType string
ServerID int
HttpPort string
ServerOpenTime string
ServerName string
ListenAddr string
CenterAddr string
CenterNode int
RemoteAddr string
GameConfPath string
TELOGDIR string
GoogleVerify bool
Partition int
KafkaHost string
KafkaPort string
Version string
CountryCode string
IdVerify bool
}
func init() {
filePath := "conf/server.json"
if len(os.Args) == 2 {
if os.Args[1] != "" {
filePath = os.Args[1]
}
}
file, err := os.Open(filePath)
if err != nil {
panic(err)
}
defer file.Close()
data, err := io.ReadAll(file)
if err != nil {
log.Fatal("%v", err)
}
err = json.Unmarshal(data, &Server)
if err != nil {
log.Fatal("%v", err)
}
}