config.go 1.7 KB
package config

import (
	"github.com/zeromicro/go-zero/core/stores/cache"
)

type Auth struct {
	AccessSecret string
	AccessExpire int64
}
type Config struct {
	DB struct {
		DataSource string
	} `json:",optional"`
	Cache  cache.CacheConf `json:",optional"`
	DTM    DTM             `json:",optional"`
	Sms    Sms             `json:",optional"`
	Oss    Oss             `json:",optional"`
	Wechat Wechat          `json:",optional"`
}

type DTM struct {
	Server Server `json:",optional"`
}

type Server struct {
	Name    string  `json:",optional"`
	Host    string  `json:",optional"`
	GRPC    GRPC    `json:",optional"`
	HTTP    HTTP    `json:",optional"`
	Metrics Metrics `json:",optional"`
}

type HTTP struct {
	Port string
}

type GRPC struct {
	Port string
}

type Metrics struct {
	Port string
}

type Sms struct {
	Debug       bool
	DebugCode   string
	Expire      int `json:",default=180"`
	MaxSendTime int `json:",default=5"`
	CompanyName string
	SecretId    string
	SecretKey   string
	SmsAppId    string
	Sign        string
	TemplateId  string
}

type Oss struct {
	OssEndPoint     string
	AccessKeyID     string
	AccessKeySecret string
	BuckName        string

	RegionID string
	RoleArn  string

	CDN CDN
}

type Wechat struct {
	AppName      string `json:",optional"`
	AppID        string
	AppSecret    string
	MsgTemplates []Template `json:",optional"`
}

func (wx Wechat) GetTemplate(code string) (Template, bool) {
	for _, temp := range wx.MsgTemplates {
		if temp.Code == code {
			return temp, true
		}
	}
	return Template{}, false
}

type CDN struct {
	HostPairs []string
}

type Template struct {
	ID   string // 模板ID
	Name string // 模板名称
	Code string // 模板编码
}