upp/property.go

57 lines
1.3 KiB
Go
Raw Normal View History

package uzone
import (
"gopkg.in/yaml.v3"
"os"
"time"
"github.com/loveuer/uzone/pkg/tool"
)
type _property struct {
Debug bool `yaml:"debug" json:"debug" arg:"env:UZONE.DEBUG"`
Listen struct {
Http string `yaml:"http" json:"http" arg:"env:UZONE.LISTEN.HTTP"`
} `yaml:"listen" json:"listen"`
DB struct {
URI string `json:"uri" arg:"env:UZONE.DB.URI"`
} `yaml:"db" json:"db"`
Cache struct {
URI string `json:"uri" arg:"env:UZONE.CACHE.URI"`
} `yaml:"cache" json:"cache"`
Elasticsearch struct {
URI string `yaml:"uri" json:"uri" arg:"env:UZONE.ELASTICSEARCH.URI"`
} `yaml:"elasticsearch" json:"elasticsearch"`
}
var property = &_property{}
func init() {
time.Local = time.FixedZone("CST", 8*3600)
var (
err error
info os.FileInfo
bs []byte
)
if info, err = os.Stat("etc/config.yaml"); err == nil && !info.IsDir() {
if bs, err = os.ReadFile("etc/config.yaml"); err != nil {
uzone_logger_pool.Get().(*uzone_logger).Warn("[%30s] read etc/config.yaml err, err = %s", "init", err.Error())
goto BindEnv
}
if err = yaml.Unmarshal(bs, property); err != nil {
uzone_logger_pool.Get().(*uzone_logger).Warn("[%30s] unmarshal etc/config.yaml err, err = %s", "init", err.Error())
}
goto BindEnv
}
BindEnv:
if property.Debug {
tool.TablePrinter(property)
}
}