conf.go 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. package conf
  2. import (
  3. "go-common/app/interface/bbq/app-bbq/api/http/v1"
  4. "go-common/library/cache/redis"
  5. "go-common/library/conf/paladin"
  6. "go-common/library/database/sql"
  7. ecode "go-common/library/ecode/tip"
  8. "go-common/library/log"
  9. "go-common/library/log/infoc"
  10. bm "go-common/library/net/http/blademaster"
  11. "go-common/library/net/http/blademaster/middleware/antispam"
  12. "go-common/library/net/http/blademaster/middleware/auth"
  13. "go-common/library/net/http/blademaster/middleware/verify"
  14. "go-common/library/net/rpc/warden"
  15. "go-common/library/net/trace"
  16. "github.com/BurntSushi/toml"
  17. )
  18. var (
  19. // Conf config
  20. Conf = &Config{}
  21. // App setting
  22. App = &AppSetting{}
  23. // Filter .
  24. Filter = &UploadFilter{}
  25. )
  26. // Config .
  27. type Config struct {
  28. Log *log.Config
  29. BM *bm.ServerConfig
  30. Verify *verify.Config
  31. Auth *auth.Config
  32. Tracer *trace.Config
  33. Redis *redis.Config
  34. MySQL *sql.Config
  35. DMMySQL *sql.Config
  36. Ecode *ecode.Config
  37. HTTPClient *HTTPClient
  38. GRPCClient map[string]*GRPCConf
  39. AntiSpam map[string]*antispam.Config
  40. Tmap map[string]string
  41. URLs map[string]string
  42. Comment *Comment
  43. Infoc *infoc.Config
  44. Search *Search
  45. Notices []*v1.NoticeOverview
  46. Upload *Upload
  47. }
  48. //Upload ..
  49. type Upload struct {
  50. HTTPSchema string
  51. }
  52. // Set .
  53. func (c *Config) Set(text string) error {
  54. if _, err := toml.Decode(text, c); err != nil {
  55. panic(err)
  56. }
  57. if c.Redis != nil {
  58. for _, anti := range c.AntiSpam {
  59. anti.Redis = c.Redis
  60. }
  61. }
  62. return nil
  63. }
  64. // Comment 评论配置
  65. type Comment struct {
  66. Type int64
  67. DebugID int64
  68. CloseRead bool
  69. CloseWrite bool
  70. }
  71. // Search 搜索配置
  72. type Search struct {
  73. Host string
  74. }
  75. // HTTPClient conf
  76. type HTTPClient struct {
  77. Normal *bm.ClientConfig
  78. Slow *bm.ClientConfig
  79. }
  80. //GRPCConf .
  81. type GRPCConf struct {
  82. WardenConf *warden.ClientConfig
  83. Addr string
  84. }
  85. // Init init conf
  86. func Init() (err error) {
  87. if err = paladin.Init(); err != nil {
  88. return
  89. }
  90. if err = paladin.Watch("video-c.toml", Conf); err != nil {
  91. return
  92. }
  93. if err = paladin.Watch("app_setting.toml", App); err != nil {
  94. return
  95. }
  96. if err = paladin.Watch("upload_filter.toml", Filter); err != nil {
  97. return
  98. }
  99. return
  100. }