app_conf.go 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. package v1
  2. import (
  3. "context"
  4. v1appconfpb "go-common/app/interface/live/app-interface/api/http/v1"
  5. "go-common/app/interface/live/app-interface/conf"
  6. titansSdk "go-common/app/service/live/resource/sdk"
  7. "go-common/library/ecode"
  8. "go-common/library/log"
  9. )
  10. //AppConfService struct
  11. type AppConfService struct {
  12. conf *conf.Config
  13. }
  14. // NewAppConfService init
  15. func NewAppConfService(c *conf.Config) (s *AppConfService) {
  16. s = &AppConfService{
  17. conf: c,
  18. }
  19. InitTitan()
  20. return s
  21. }
  22. //GetConf 获取移动端配置
  23. func (s *AppConfService) GetConf(ctx context.Context, req *v1appconfpb.GetConfReq) (resp *v1appconfpb.GetConfResp, err error) {
  24. value, ok := s.conf.AppConf[req.GetKey()]
  25. if !ok {
  26. log.Error("[AppConf] GetConf Key err: %s", req.GetKey())
  27. return nil, ecode.AppConfKeyErr
  28. }
  29. resp = &v1appconfpb.GetConfResp{
  30. Value: value,
  31. }
  32. conf, terr := titansSdk.Get(req.GetKey())
  33. if terr != nil {
  34. log.Error("[AppConf] GetConf titansSdk.Get err: %+v", err)
  35. }
  36. if conf != "" {
  37. resp.Value = conf
  38. }
  39. return
  40. }
  41. //InitTitan 初始化kv配置
  42. func InitTitan() {
  43. conf := &titansSdk.Config{
  44. TreeId: 61019,
  45. Expire: 1,
  46. }
  47. titansSdk.Init(conf)
  48. }