main
kzkzzzz 2024-06-23 13:15:47 +08:00
parent 26bf8320e3
commit abce1f5c8d
1 changed files with 8 additions and 0 deletions

View File

@ -2,6 +2,7 @@ package myconf
import (
"fmt"
"github.com/spf13/pflag"
"github.com/spf13/viper"
)
@ -9,6 +10,13 @@ var (
vp = viper.New()
)
func LoadFlag() {
err := vp.BindPFlags(pflag.CommandLine)
if err != nil {
panic(fmt.Errorf("load command line fail: %s", err))
}
}
func LoadFile(confFile string, conf interface{}) {
vp.SetConfigFile(confFile)
err := vp.ReadInConfig()