123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110 |
- package config
- import (
- "gopkg.in/yaml.v2"
- "os"
- "sync"
- )
- var (
- instance *config
- once sync.Once
- )
- func init() {
- once.Do(func() {
- var conf config
- path, _ := os.Getwd()
- filePath := path + "/config/config.yaml"
- if f, err := os.Open(filePath); err != nil {
- panic(err)
- } else {
- err := yaml.NewDecoder(f).Decode(&conf)
- if err != nil {
- panic(err)
- }
- }
- instance = &conf
- })
- }
- // 获取配置文档实例
- func Instance() *config {
- return instance
- }
- type config struct {
- Server server `yaml:"server"`
- Database database `yaml:"database"`
- Redis redis `yaml:"redis"`
- Logger logger `yaml:"logger"`
- Minio minio `yaml:"minio"`
- Foreign foreign `yaml:"foreign"`
- MonitNotice monitNotice `yaml:"monit-notice"`
- Es es `yaml:"es"`
- }
- type server struct {
- Address string `yaml:"address"`
- CodeEnabled bool `yaml:"code_enabled"`
- TokenSign string `yaml:"token_sign"`
- }
- type database struct {
- Host string `yaml:"host"`
- Auth string `yaml:"Auth"`
- Password string `yaml:"password"`
- Port string `yaml:"port"`
- Name string `yaml:"name"`
- Timezone string `yaml:"timezone"`
- }
- type redis struct {
- Host string `yaml:"host"`
- Password string `yaml:"password"`
- }
- type logger struct {
- Switch int `yaml:"switch"`
- Path string `yaml:"path"`
- Name string `yaml:"name"`
- Level string `yaml:"level"`
- DbShowLog int `yaml:"db_show_log"`
- }
- type minio struct {
- Endpoint string `yaml:"endpoint"`
- Link string `yaml:"link"`
- AccessKey string `yaml:"access_key"`
- SecretKey string `yaml:"secret_key"`
- }
- type foreign struct {
- IotEdgeUrl string `yaml:"iot_edge_url"`
- IpCastEdgeUrl string `yaml:"ip_cast_edge_url"`
- SecurityRewindUrl string `yaml:"security_rewind_url"`
- }
- type email struct {
- Host string `yaml:"host"`
- Port string `yaml:"port"`
- AuthName string `yaml:"Auth-name"`
- PassWord string `yaml:"pass-word"`
- }
- type tencent struct {
- AppID string `yaml:"app_id"`
- SecretID string `yaml:"secret_id"`
- SecretKey string `yaml:"secret_key"`
- SmsKey string `yaml:"sms_key"`
- WarnSmsTemplateID string `yaml:"warn_sms_template_id"`
- }
- type sms struct {
- Tencent tencent `yaml:"tencent"`
- }
- type monitNotice struct {
- Email email `yaml:"email"`
- Sms sms `yaml:"sms"`
- }
- type es struct {
- URL string `yaml:"es_url"`
- }
|