接收配置的必须是指针对象
This commit is contained in:
@@ -4,10 +4,12 @@ package viperx
|
|||||||
// Version: 2023年6月12日18:54:48
|
// Version: 2023年6月12日18:54:48
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"errors"
|
||||||
"flag"
|
"flag"
|
||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
"log"
|
||||||
"os"
|
"os"
|
||||||
|
"reflect"
|
||||||
|
|
||||||
"github.com/fsnotify/fsnotify"
|
"github.com/fsnotify/fsnotify"
|
||||||
"github.com/spf13/viper"
|
"github.com/spf13/viper"
|
||||||
@@ -17,6 +19,11 @@ import (
|
|||||||
|
|
||||||
func InitConfig(path string, data interface{}) error {
|
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 {
|
if len(path) == 0 {
|
||||||
flag.StringVar(&path, "c", "", "choose config file.")
|
flag.StringVar(&path, "c", "", "choose config file.")
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
|
|||||||
Reference in New Issue
Block a user