代码拉取完成,页面将自动刷新
package conf
import (
"context"
"gitee.com/byx_darwin/micro-extend/pkg/config/kitex_conf"
"gitee.com/byx_darwin/uptrace-opentelemetry/log"
"github.com/bytedance/go-tagexpr/v2/validator"
"github.com/cloudwego/kitex/pkg/klog"
"gopkg.in/yaml.v3"
"os"
"path/filepath"
"sync"
)
var (
conf *Config
once sync.Once
)
type Config struct {
Service kitex_conf.Service `json:"service" yaml:"service"`
Server kitex_conf.Server `json:"server" yaml:"server"`
Logger log.Config `json:"logger" yaml:"logger"`
GeoOption GeoOption `json:"geo_option" yaml:"geo_option"`
}
type GeoOption struct {
Language string `json:"language" yaml:"language"`
Ip2RegionPath string `json:"ip2_region_path" yaml:"ip2_region_path"`
GeoIPCityPath string `json:"geoip_city_path" yaml:"geoip_city_path"`
GeoIPIspPath string `json:"geoip_isp_path" yaml:"geoip_isp_path"`
CacheSize int `json:"cache_size" yaml:"cache_size"`
}
// GetConf gets configuration instance
func GetConf() *Config {
once.Do(initConf)
return conf
}
func initConf() {
prefix := "conf"
confFileRelPath := filepath.Join(prefix, filepath.Join(GetEnv(), "conf.yaml"))
content, err := os.ReadFile(confFileRelPath)
ctx := context.Background()
if err != nil {
klog.CtxFatalf(ctx, "read conf.yaml error - %v", err)
panic(err)
}
conf = new(Config)
err = yaml.Unmarshal(content, conf)
if err != nil {
klog.CtxFatalf(ctx, "parse yaml error - %v", err)
}
if err := validator.Validate(conf); err != nil {
klog.Error("validate config error - %v", err)
panic(err)
}
}
func GetEnv() string {
e := os.Getenv("GO_ENV")
if len(e) == 0 {
return "dev"
}
return e
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。