config.go 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. package config
  2. import (
  3. "app.yhyue.com/moapp/jybase/common"
  4. "app.yhyue.com/moapp/jypkg/middleground"
  5. "github.com/gogf/gf/v2/frame/g"
  6. "github.com/gogf/gf/v2/os/gctx"
  7. "github.com/gogf/gf/v2/os/gcfg"
  8. )
  9. type appConfig struct {
  10. WebPort string `json:"webport"` //程序端口
  11. AppId string `json:"appid"` //程序标识
  12. OssAdmin string `json:"ossAdmin"` //阿里云oss域名
  13. OssBucket struct {
  14. Std string `json:"std"` //标准库bucket
  15. User string `json:"user"` //用户库
  16. Priv string `json:"priv"` //缩略图片
  17. } `json:"ossBucket"` //阿里云ossbucket
  18. RpcServers struct {
  19. StdDoc rpcConfig `json:"stdDoc"` //标准库rpc接口
  20. UserDoc rpcConfig `json:"userDoc"` //用户收藏rpc接口
  21. Points rpcConfig `json:"points"` //剑鱼积分rpc接口
  22. JyFile rpcConfig `json:"jyFile"` //剑鱼文件rpc接口
  23. } `json:"rpcServers"` //rpc服务配置
  24. IndexSearchTag []string `json:"indexSearchTag"` //首页标签
  25. SearchNumLimit int64 `json:"searchNumLimit"` //检索条数限制
  26. ShareUrl string `json:"shareUrl"` //分享地址
  27. DoudingImg string `json:"doudingImg"` // 豆丁封面图片地址
  28. Price map[int64]map[int64]struct {
  29. Rate int64 `json:"rate"` // 价格转换比率
  30. Base int64 `json:"base"` // 价格基数
  31. } `json:"price"`
  32. DocMember struct {
  33. Times int `json:"times"` // 会员免费下载次数
  34. Discount int64 `json:"discount"` // 会员折扣
  35. Source []string `json:"source"` // 留资source
  36. } `json:"docMember"`
  37. }
  38. /*
  39. 例如
  40. "price": {
  41. "2": { // 对应文档来源 文档来源:;2:豆丁;
  42. "1": { // 对应商品类型 1:会员免费;2:精品(付费)
  43. "rate": 0, // 比率
  44. "base": 50 // 基数 例如会员免费文档 50+0*price = 50
  45. },
  46. "2": {
  47. "rate": 100, // 例如 精品 100+100*price
  48. "base": 100
  49. }
  50. }
  51. }
  52. */
  53. type rpcConfig struct {
  54. Key string `json:"key"`
  55. Address []string `json:"address"` //集群地址
  56. }
  57. var JyDocsAppConfig appConfig
  58. var Middleground *middleground.Middleground
  59. func init() {
  60. g.Cfg().GetAdapter().(*gcfg.AdapterFile).SetFileName("config.yaml")
  61. var ctx = gctx.New()
  62. Middleground = middleground.NewMiddleground(g.Cfg().MustGet(ctx, "etcd.hosts").Strings()).
  63. RegUserCenter(g.Cfg().MustGet(ctx, "userCenterKey").String())
  64. common.ReadConfig(&JyDocsAppConfig)
  65. }