189 lines
5.3 KiB
Go
189 lines
5.3 KiB
Go
package service
|
|
|
|
import (
|
|
"fmt"
|
|
"service/api/base"
|
|
"service/api/consts"
|
|
"service/api/errcode"
|
|
"service/apollostruct"
|
|
"service/library/apollo"
|
|
"service/library/logger"
|
|
"strconv"
|
|
"strings"
|
|
|
|
"github.com/gin-gonic/gin"
|
|
)
|
|
|
|
var (
|
|
DefaultConfigService *ConfigService
|
|
)
|
|
|
|
type ConfigService struct {
|
|
}
|
|
|
|
func NewConfigService() *ConfigService {
|
|
return new(ConfigService)
|
|
}
|
|
|
|
func (s *ConfigService) OpGetStreamerTagList(ctx *gin.Context) (supportWxIdMap map[int64]string, ec errcode.ErrCode) {
|
|
ec = errcode.ErrCodeOk
|
|
|
|
supportWxIdMap = make(map[int64]string, 16)
|
|
|
|
tagNum, err := apollo.GetIntValue(consts.TagNumKey, apollo.ApolloOpts().SetNamespace("tag"))
|
|
if err != nil {
|
|
logger.Error("Apollo read failed : %v", err)
|
|
return nil, errcode.ErrCodeApolloReadFail
|
|
}
|
|
|
|
for i := 0; i < tagNum; i++ {
|
|
curTag, err := apollo.GetStringValue(fmt.Sprintf("%d", i), apollo.ApolloOpts().SetNamespace("tag"))
|
|
if err != nil {
|
|
logger.Error("Apollo read failed : %v", err)
|
|
return nil, errcode.ErrCodeApolloReadFail
|
|
}
|
|
supportWxIdMap[int64(i)] = curTag
|
|
}
|
|
|
|
return
|
|
}
|
|
|
|
func (s *ConfigService) OpGetPlatformList(ctx *gin.Context) (platformMap map[int64]*apollostruct.PlatformCfg, ec errcode.ErrCode) {
|
|
|
|
ec = errcode.ErrCodeOk
|
|
|
|
platformNum, err := apollo.GetIntValue(consts.PlatformNumKey, apollo.ApolloOpts().SetNamespace("platform"))
|
|
if err != nil {
|
|
logger.Error("Apollo read failed : %v", err)
|
|
return nil, errcode.ErrCodeApolloReadFail
|
|
}
|
|
|
|
platformMap = make(map[int64]*apollostruct.PlatformCfg)
|
|
|
|
for i := 0; i < platformNum; i++ {
|
|
cfg := &apollostruct.PlatformCfg{}
|
|
err = apollo.GetJson(fmt.Sprintf("%d", i), cfg, apollo.ApolloOpts().SetNamespace("platform"))
|
|
if err != nil {
|
|
logger.Error("Apollo read failed : %v", err)
|
|
return nil, errcode.ErrCodeApolloReadFail
|
|
}
|
|
if cfg.IsDeleted == 0 {
|
|
platformMap[int64(i)] = cfg
|
|
}
|
|
}
|
|
|
|
return
|
|
}
|
|
|
|
func (s *ConfigService) OpGetSupportWxIdList(ctx *gin.Context) (supportWxIdMap map[int64]string, ec errcode.ErrCode) {
|
|
ec = errcode.ErrCodeOk
|
|
|
|
supportWxIdMap = make(map[int64]string)
|
|
|
|
tagNum, err := apollo.GetIntValue(consts.SupportWxIdNumKey, apollo.ApolloOpts().SetNamespace("support_wx_id"))
|
|
if err != nil {
|
|
logger.Error("Apollo read failed : %v", err)
|
|
return nil, errcode.ErrCodeApolloReadFail
|
|
}
|
|
|
|
for i := 0; i < tagNum; i++ {
|
|
curTag, err := apollo.GetStringValue(fmt.Sprintf("%d", i), apollo.ApolloOpts().SetNamespace("support_wx_id"))
|
|
if err != nil {
|
|
logger.Error("Apollo read failed : %v", err)
|
|
return nil, errcode.ErrCodeApolloReadFail
|
|
}
|
|
supportWxIdMap[int64(i)] = curTag
|
|
}
|
|
|
|
return
|
|
}
|
|
|
|
func (s *ConfigService) OpIsThereANewVersionAvailable(ctx *gin.Context, baseRequest *base.BaseRequest) (result bool, version *apollostruct.Version, ec errcode.ErrCode) {
|
|
ec = errcode.ErrCodeOk
|
|
result = false
|
|
|
|
var key string
|
|
if baseRequest.DevType == consts.DevType_Android {
|
|
key = consts.AndroidKey
|
|
} else if baseRequest.DevType == consts.DevType_Ios {
|
|
key = consts.IosKey
|
|
}
|
|
ver := &apollostruct.Version{}
|
|
err := apollo.GetJson(key, ver, apollo.ApolloOpts().SetNamespace("version"))
|
|
if err != nil {
|
|
logger.Error("Apollo read failed : %v", err)
|
|
ec = errcode.ErrCodeApolloReadFail
|
|
return
|
|
}
|
|
|
|
appVersionSeqNos := strings.Split(ver.Version, ".")
|
|
userVersionSeqNos := strings.Split(baseRequest.Version, ".")
|
|
if len(appVersionSeqNos) != len(userVersionSeqNos) {
|
|
logger.Error("User version format error")
|
|
ec = errcode.ErrCodeApolloVersionFormatError
|
|
return
|
|
}
|
|
for i := range appVersionSeqNos {
|
|
appVersionSeqNo, err := strconv.Atoi(appVersionSeqNos[i])
|
|
if err != nil {
|
|
logger.Error("Apollo version format error")
|
|
ec = errcode.ErrCodeApolloVersionFormatError
|
|
return
|
|
}
|
|
userVersionSeqNo, err := strconv.Atoi(userVersionSeqNos[i])
|
|
if err != nil {
|
|
logger.Error("User version format error")
|
|
ec = errcode.ErrCodeUserVersionFormatError
|
|
return
|
|
}
|
|
if appVersionSeqNo > userVersionSeqNo {
|
|
result = true
|
|
break
|
|
} else if appVersionSeqNo < userVersionSeqNo {
|
|
break
|
|
}
|
|
}
|
|
if result {
|
|
version = ver
|
|
}
|
|
return
|
|
}
|
|
|
|
func (s *ConfigService) OpGetUploadMediaFailConfigList(ctx *gin.Context) (uploadMediaFailConfigMap map[string]int64, ec errcode.ErrCode) {
|
|
ec = errcode.ErrCodeOk
|
|
|
|
uploadMediaFailConfigMap = make(map[string]int64)
|
|
|
|
imageIdForUploadFail, err := apollo.GetIntValue(consts.ImageIdForUploadFail, apollo.ApolloOpts().SetNamespace("application"))
|
|
if err != nil {
|
|
logger.Error("Apollo read failed : %v", err)
|
|
return nil, errcode.ErrCodeApolloReadFail
|
|
}
|
|
|
|
videoIdForUploadFail, err := apollo.GetIntValue(consts.VideoIdForUploadFail, apollo.ApolloOpts().SetNamespace("application"))
|
|
if err != nil {
|
|
logger.Error("Apollo read failed : %v", err)
|
|
return nil, errcode.ErrCodeApolloReadFail
|
|
}
|
|
|
|
uploadMediaFailConfigMap["image_id_for_upload_fail"] = int64(imageIdForUploadFail)
|
|
uploadMediaFailConfigMap["video_id_for_upload_fail"] = int64(videoIdForUploadFail)
|
|
|
|
return
|
|
}
|
|
|
|
func (s *ConfigService) OpGetIsMomentImageEncryptEnabled(ctx *gin.Context) (isEnabled int64, ec errcode.ErrCode) {
|
|
ec = errcode.ErrCodeOk
|
|
|
|
isMomentImageEncryptEnabled, err := apollo.GetIntValue(consts.IsMomentImageEncryptEnabledKey, apollo.ApolloOpts().SetNamespace("application"))
|
|
if err != nil {
|
|
logger.Error("Apollo read failed : %v", err)
|
|
ec = errcode.ErrCodeApolloReadFail
|
|
return
|
|
}
|
|
|
|
isEnabled = int64(isMomentImageEncryptEnabled)
|
|
|
|
return
|
|
}
|