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.

31 lines
621 B

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