From b3a11e616ba59e4315b5b3edf147d632239c6990 Mon Sep 17 00:00:00 2001 From: Yun Date: Wed, 13 Mar 2024 14:16:45 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8E=A5=E6=94=B6=E9=85=8D=E7=BD=AE=E7=9A=84?= =?UTF-8?q?=E5=BF=85=E9=A1=BB=E6=98=AF=E6=8C=87=E9=92=88=E5=AF=B9=E8=B1=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- viperx.go | 7 +++++++ 1 file changed, 7 insertions(+) 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()