diff --git a/viperx.go b/viperx.go index efefd38..0c138d1 100644 --- a/viperx.go +++ b/viperx.go @@ -4,10 +4,12 @@ package viperx // Version: 2023年6月12日18:54:48 import ( + "errors" "flag" "fmt" "log" "os" + "reflect" "github.com/fsnotify/fsnotify" "github.com/spf13/viper" @@ -17,6 +19,11 @@ import ( func InitConfig(path string, data interface{}) error { + // 判断是否指针 + if reflect.ValueOf(data).Kind() != reflect.Ptr { + return errors.New("data must be a pointer") + } + if len(path) == 0 { flag.StringVar(&path, "c", "", "choose config file.") flag.Parse()