app.go 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. package config
  2. import (
  3. "kpt-tmr-group/pkg/di"
  4. "os"
  5. "strings"
  6. "sync"
  7. )
  8. const AppName = "kptEvent"
  9. var (
  10. Module = di.Provide(Options)
  11. options *AppConfig
  12. appEnv string
  13. initOnce sync.Once
  14. )
  15. // AppConfig store all configuration options
  16. type AppConfig struct {
  17. AppName string `yaml:"app_name"`
  18. AppEnv string `yaml:"app_environment"`
  19. Debug bool `yaml:"debug" env:"APP_DEBUG"`
  20. HTTPServerAddr string `yaml:"http_server_addr" env:"HTTP_SERVER_ADDR"`
  21. // 数据库配置 额外加载文件部分 database.yaml
  22. StoreSetting StoreSetting `json:"storeSetting" yaml:"store"`
  23. // redis 配置
  24. RedisSetting RedisSetting `json:"RedisSetting" yaml:"redis_setting"`
  25. JwtSecret string `json:"jwtSecret" yaml:"jwt_secret"`
  26. ExcelSetting ExcelSetting `json:"excelSetting" yaml:"excel_setting"`
  27. WechatSetting WechatSetting `json:"wechatSetting" yaml:"wechat_setting"`
  28. }
  29. type WechatSetting struct {
  30. Appid string `yaml:"appid"`
  31. Secret string `yaml:"secret"`
  32. }
  33. type ExcelSetting struct {
  34. SheetName string `yaml:"sheet_name"` // = "Sheet1" //默认Sheet名称
  35. Height float64 `yaml:"height"` // = 25.0 //默认行高度
  36. }
  37. // StoreSetting 数据库配置
  38. type StoreSetting struct {
  39. // 开启 SyDb SQL 记录
  40. DriverName string `yaml:"driver_name" json:"driver_name"`
  41. ShowSQL bool `yaml:"show_sql" env:"STORE_SHOW_SQL"`
  42. KptEventDSNRW string `yaml:"kpt_tmr_group_rw" env:"LINGO_COURSE_DSN_RW"`
  43. KptEventDSNMigr string `yaml:"kpt_tmr_group_migr" env:"LINGO_COURSE_DSN_MIGR"`
  44. }
  45. type RedisSetting struct {
  46. // sso 配置
  47. SSOCache SSOCache `json:"SSOCache" yaml:"sso_cache"`
  48. }
  49. type SSOCache struct {
  50. Addr string `json:"addr" yaml:"addr"`
  51. Requirepass string `json:"requirepass" yaml:"requirepass"`
  52. DB int `json:"DB" yaml:"DB"`
  53. Expiry int `json:"expiry" yaml:"expiry"`
  54. }
  55. func Options() *AppConfig {
  56. return options
  57. }
  58. func init() {
  59. appEnv = strings.ToLower(os.Getenv("APP_ENVIRONMENT"))
  60. cfg := &AppConfig{}
  61. var err error
  62. initOnce.Do(func() {
  63. switch appEnv {
  64. default:
  65. err = Initialize("app.test.yaml", cfg)
  66. case "development":
  67. err = Initialize("app.develop.yaml", cfg)
  68. case "production":
  69. err = Initialize("app.production.yaml", cfg)
  70. }
  71. if err != nil {
  72. panic(err)
  73. }
  74. options = cfg
  75. })
  76. }