config.go 2.3 KB
package config

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

type JWT struct {
	Secret  string        `json:",optional"`
	Expires time.Duration `json:",optional"`
}
type JwtAuth struct {
	AccessSecret string
	Expire       int64
}
type Config struct {
	JwtAuth    JwtAuth            `json:",optional"`
	UserRpc    zrpc.RpcClientConf `json:",optional"`
	AuthRpc    zrpc.RpcClientConf `json:",optional"`
	PostRpc    zrpc.RpcClientConf `json:",optional"`
	CommentRpc zrpc.RpcClientConf `json:",optional"`
	JWT        JWT                `json:",optional"`
	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"` // 学员端微信
	CoachClient     Wechat          `json:",optional"` // 教练端微信
	OfficialAccount Wechat          `json:",optional"`
	ThirdWechatApps []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 // 模板编码
}