You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

71 lines
1.4 KiB

package entity
import (
"encoding/json"
"fmt"
"os"
"tools/logic/redis"
)
type ResultPo struct {
Code int
Msg string
PayLoad interface{}
Data interface{}
}
type Config struct {
Host string `json:"host"`
Script string `json:"script"`
Redis string `json:"redis"`
Type string `json:"type"`
Log string `json:"log"`
CronHost string `json:"cronHost"`
}
var redisClient *redis.Client
const CONFIG_PATH = "conf/"
func Load(path string) {
config := Config{}
fmt.Println("input config file path=" + path)
configBytes, err := os.ReadFile(path)
if err != nil {
path = CONFIG_PATH + "default/config.json"
configBytes, err = os.ReadFile(path)
if err != nil {
path = CONFIG_PATH + "config.json"
configBytes, err = os.ReadFile(path)
if err != nil {
fmt.Println("not found config=" + path)
config.Redis = "127.0.0.1:2379"
config.Host = "127.0.0.1:7890"
config.Script = ""
fmt.Println("load default config")
serverConf = config
return
}
}
}
fmt.Println("load file=" + path)
err = json.Unmarshal(configBytes, &config)
if err != nil {
panic("[configMgr][err][marshal config filed]" + err.Error())
return
}
serverConf = config
redisClient, err = redis.NewClient(serverConf.Redis, "")
if err != nil {
panic("redis error" + err.Error())
}
}
var serverConf Config
func GetConf() Config {
return serverConf
}
func GetRedis() *redis.Client {
return redisClient
}