pet_home_server/src/server/conf/json.go
2025-07-14 16:13:22 +08:00

79 lines
1.2 KiB
Go

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
GameName string
ServerType string
ServerID int
HttpPort string
ServerOpenTime string
ServerName string
ListenAddr string
CenterAddr string
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)
}
}