app.go 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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. }
  28. type ExcelSetting struct {
  29. SheetName string `yaml:"sheet_name"` // = "Sheet1" //默认Sheet名称
  30. Height float64 `yaml:"height"` // = 25.0 //默认行高度
  31. }
  32. // StoreSetting 数据库配置
  33. type StoreSetting struct {
  34. // 开启 SyDb SQL 记录
  35. DriverName string `yaml:"driver_name" json:"driver_name"`
  36. ShowSQL bool `yaml:"show_sql" env:"STORE_SHOW_SQL"`
  37. KptEventDSNRW string `yaml:"kpt_tmr_group_rw" env:"LINGO_COURSE_DSN_RW"`
  38. KptEventDSNMigr string `yaml:"kpt_tmr_group_migr" env:"LINGO_COURSE_DSN_MIGR"`
  39. }
  40. type RedisSetting struct {
  41. // sso 配置
  42. SSOCache SSOCache `json:"SSOCache" yaml:"sso_cache"`
  43. }
  44. type SSOCache struct {
  45. Addr string `json:"addr" yaml:"addr"`
  46. Requirepass string `json:"requirepass" yaml:"requirepass"`
  47. DB int `json:"DB" yaml:"DB"`
  48. Expiry int `json:"expiry" yaml:"expiry"`
  49. }
  50. func Options() *AppConfig {
  51. return options
  52. }
  53. func init() {
  54. appEnv = strings.ToLower(os.Getenv("APP_ENVIRONMENT"))
  55. cfg := &AppConfig{}
  56. var err error
  57. initOnce.Do(func() {
  58. switch appEnv {
  59. default:
  60. err = Initialize("app.test.yaml", cfg)
  61. case "development":
  62. err = Initialize("app.develop.yaml", cfg)
  63. case "production":
  64. err = Initialize("app.production.yaml", cfg)
  65. }
  66. if err != nil {
  67. panic(err)
  68. }
  69. options = cfg
  70. })
  71. }