接收配置的必须是指针对象
This commit is contained in:
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user