You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

49 lines
1.0 KiB

  1. package config
  2. import (
  3. "fmt"
  4. "github.com/fsnotify/fsnotify"
  5. "github.com/spf13/viper"
  6. )
  7. type Config struct {
  8. MysqlAdmin MysqlAdmin
  9. Qiniu Qiniu
  10. CasbinConfig CasbinConfig
  11. }
  12. type CasbinConfig struct {
  13. ModelPath string // casbin model地址配置
  14. }
  15. type MysqlAdmin struct { // mysql admin 数据库配置
  16. Username string
  17. Password string
  18. Path string
  19. Dbname string
  20. Config string
  21. }
  22. type Qiniu struct { // 七牛 密钥配置
  23. AccessKey string
  24. SecretKey string
  25. }
  26. var GinVueAdminconfig Config
  27. func init() {
  28. v := viper.New()
  29. v.SetConfigName("config") // 设置配置文件名 (不带后缀)
  30. v.AddConfigPath("./static/config/") // 第一个搜索路径
  31. v.SetConfigType("json")
  32. err := v.ReadInConfig() // 搜索路径,并读取配置数据
  33. if err != nil {
  34. panic(fmt.Errorf("Fatal error config file: %s \n", err))
  35. }
  36. v.WatchConfig()
  37. v.OnConfigChange(func(e fsnotify.Event) {
  38. fmt.Println("Config file changed:", e.Name)
  39. })
  40. if err := v.Unmarshal(&GinVueAdminconfig); err != nil {
  41. fmt.Println(err)
  42. }
  43. }