接收配置的必须是指针对象

This commit is contained in:
Yun
2024-03-13 14:16:45 +08:00
parent d5217ba990
commit b3a11e616b
+7
View File
@@ -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()