代码拉取完成,页面将自动刷新
package helper
import (
"fmt"
"os"
"gitee.com/ander888/tools/model"
"gitee.com/ander888/tools/zlog"
"gopkg.in/yaml.v3"
)
type GatewayConfSt struct {
EtcdConf model.EtcdConf `json:"etcd_conf" yaml:"etcd_conf"`
SqlCnf model.SQLConf `json:"sql_cnf" yaml:"sql_cnf"`
MinioCnf model.MinioConf `json:"minio_cnf" yaml:"minio_cnf"`
LogCnf model.LogConf `json:"log_cnf" yaml:"log_cnf"`
}
type VideoConfSt struct {
EtcdConf model.EtcdConf `json:"etcd_conf" yaml:"etcd_conf"`
MinioCnf model.MinioConf `json:"minio_cnf" yaml:"minio_cnf"`
LogCnf model.LogConf `json:"log_cnf" yaml:"log_cnf"`
}
type ScheduleConfSt struct {
EtcdConf model.EtcdConf `json:"etcd_conf" yaml:"etcd_conf"`
MinioCnf model.MinioConf `json:"minio_cnf" yaml:"minio_cnf"`
LogCnf model.LogConf `json:"log_cnf" yaml:"log_cnf"`
}
type PredictConfSt struct {
EtcdConf model.EtcdConf `json:"etcd_conf" yaml:"etcd_conf"`
LogCnf model.LogConf `json:"log_cnf" yaml:"log_cnf"`
}
// GetGatewayConfByYml 按配置文件获取配置信息
func GetGatewayConfByYml(cnfPath string) (env GatewayConfSt) {
if len(cnfPath) == 0 {
cnfPath = "../conf/gateway_default.yaml"
}
dataBytes, err := os.ReadFile(cnfPath)
CheckErrorWithPanic(err, "读取配置文件失败,请检查配置文件:", cnfPath)
err = yaml.Unmarshal(dataBytes, &env)
CheckErrorWithPanic(err, "反序列化配置文件失败:", env)
return env
}
// GetVideoConfByYml 按配置文件获取配置信息
func GetVideoConfByYml(cnfPath string) (env VideoConfSt) {
if len(cnfPath) == 0 {
cnfPath = "../conf/video_default.yaml"
}
dataBytes, err := os.ReadFile(cnfPath)
CheckErrorWithPanic(err, "读取配置文件失败,请检查配置文件:", cnfPath)
err = yaml.Unmarshal(dataBytes, &env)
CheckErrorWithPanic(err, "反序列化配置文件失败:", env)
return env
}
// GetScheduleConfByYml 按配置文件获取配置信息
func GetScheduleConfByYml(cnfPath string) (env ScheduleConfSt) {
if len(cnfPath) == 0 {
cnfPath = "../conf/schedule_default.yaml"
}
dataBytes, err := os.ReadFile(cnfPath)
CheckErrorWithPanic(err, "读取配置文件失败,请检查配置文件:", cnfPath)
err = yaml.Unmarshal(dataBytes, &env)
CheckErrorWithPanic(err, "反序列化配置文件失败:", env)
return env
}
// GetPredictConfByYml 按配置文件获取配置信息
func GetPredictConfByYml(cnfPath string) (env PredictConfSt) {
if len(cnfPath) == 0 {
cnfPath = "../conf/predict_default.yaml"
}
dataBytes, err := os.ReadFile(cnfPath)
CheckErrorWithPanic(err, "读取配置文件失败,请检查配置文件:", cnfPath)
err = yaml.Unmarshal(dataBytes, &env)
CheckErrorWithPanic(err, "反序列化配置文件失败:", env)
return env
}
func GetYamlConf(cnfPath string, configStruct interface{}) {
// 设置默认配置文件
if !fileExists(cnfPath) {
zlog.WarnWithStr().Any("当前传入的配置文件不存在:", cnfPath).Any(" 已设置为默认配置文件", "./conf/default.yaml")
cnfPath = "./conf/default.yaml"
}
// Read YAML file
yamlFile, err := os.ReadFile(cnfPath)
if err != nil {
CheckErrorWithPanic(err, "读取配置文件失败,请检查配置文件:", cnfPath)
}
// 将解析后的配置信息转换为具体的结构体
err = yaml.Unmarshal(yamlFile, configStruct)
if err != nil {
CheckErrorWithPanic(err, "无法解析配置文件到结构体", configStruct)
}
// Print the parsed configuration
zlog.InfoWithStr().Any("配置文件为:", configStruct)
}
func CheckErrorWithPanic(err error, errDesc string, errInfo interface{}) {
if err != nil {
fmt.Printf("当前错误信息为:%s 错误为:%#v 导致错误的内容为:%#v", errDesc, err, errInfo)
zlog.ErrWithStr(err).Any(errDesc, errInfo)
}
}
func CheckError(err error, errDesc string, errInfo interface{}) {
if err != nil {
zlog.ErrWithStr(err).Any(errDesc, errInfo)
}
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。