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.

32 lines
649 B

  1. package core
  2. import (
  3. "fmt"
  4. "gin-vue-admin/global"
  5. _ "gin-vue-admin/packfile"
  6. "github.com/fsnotify/fsnotify"
  7. "github.com/spf13/viper"
  8. )
  9. const defaultConfigFile = "config.yaml"
  10. func init() {
  11. v := viper.New()
  12. v.SetConfigFile(defaultConfigFile)
  13. err := v.ReadInConfig()
  14. if err != nil {
  15. panic(fmt.Errorf("Fatal error config file: %s \n", err))
  16. }
  17. v.WatchConfig()
  18. v.OnConfigChange(func(e fsnotify.Event) {
  19. fmt.Println("config file changed:", e.Name)
  20. if err := v.Unmarshal(&global.GVA_CONFIG); err != nil {
  21. fmt.Println(err)
  22. }
  23. })
  24. if err := v.Unmarshal(&global.GVA_CONFIG); err != nil {
  25. fmt.Println(err)
  26. }
  27. global.GVA_VP = v
  28. }