config.go 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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. Docin string `json:"docin"` //豆丁的桶
  18. } `json:"ossBucket"` //阿里云ossbucket
  19. RpcServers struct {
  20. StdDoc rpcConfig `json:"stdDoc"` //标准库rpc接口
  21. UserDoc rpcConfig `json:"userDoc"` //用户收藏rpc接口
  22. Points rpcConfig `json:"points"` //剑鱼积分rpc接口
  23. JyFile rpcConfig `json:"jyFile"` //剑鱼文件rpc接口
  24. Partner rpcConfig `json:"partner"` //剑鱼文库豆丁购买和下载接口rpc接口
  25. } `json:"rpcServers"` //rpc服务配置
  26. IndexSearchTag []string `json:"indexSearchTag"` //首页标签
  27. SearchNumLimit int64 `json:"searchNumLimit"` //检索条数限制
  28. ShareUrl string `json:"shareUrl"` //分享地址
  29. DoudingImg string `json:"doudingImg"` // 豆丁封面图片地址
  30. Price map[int64]map[int64]struct {
  31. Rate int64 `json:"rate"` // 价格转换比率
  32. Base int64 `json:"base"` // 价格基数
  33. } `json:"price"`
  34. DocMember struct {
  35. Times int64 `json:"times"` // 会员免费下载次数
  36. Discount int64 `json:"discount"` // 会员折扣
  37. FreeDocLimit int64 `json:"freeDocLimit"` // 豆丁会员免费下载限制
  38. } `json:"docMember"`
  39. }
  40. /*
  41. 例如
  42. "price": {
  43. "2": { // 对应文档来源 文档来源:;2:豆丁;
  44. "1": { // 对应商品类型 1:会员免费;2:精品(付费)
  45. "rate": 0, // 比率
  46. "base": 50 // 基数 例如会员免费文档 50+0*price = 50
  47. },
  48. "2": {
  49. "rate": 100, // 例如 精品 100+100*price
  50. "base": 100
  51. }
  52. }
  53. }
  54. */
  55. type rpcConfig struct {
  56. Key string `json:"key"`
  57. Address []string `json:"address"` //集群地址
  58. Timeout int64 `json:"timeout,omitempty"` // 超时时间 毫秒
  59. }
  60. var JyDocsAppConfig appConfig
  61. var Middleground *middleground.Middleground
  62. func init() {
  63. g.Cfg().GetAdapter().(*gcfg.AdapterFile).SetFileName("config.yaml")
  64. var ctx = gctx.New()
  65. Middleground = middleground.NewMiddleground(g.Cfg().MustGet(ctx, "etcd.hosts").Strings()).
  66. RegUserCenter(g.Cfg().MustGet(ctx, "userCenterKey").String()).
  67. RegPowerCheckCenter(g.Cfg().MustGet(ctx, "powerCheckCenterKey").String())
  68. common.ReadConfig(&JyDocsAppConfig)
  69. }