官方网站: https://godoc.org/github.com/spf13/viper
go get -u -v github.com/spf13/viper
func (v *Viper) ConfigFileUsed() string
func (v *Viper) Unmarshal(rawVal interface{
}, opts ...DecoderConfigOption) error
func SetConfigFile(in string)
显式定义配置文件的路径、名称和扩展名。Viper使用时不会检查任何配置路径。
func (v *Viper) ReadInConfig() error
cat config.yaml
TimeStamp: "2019-01-02 16:26:20"
Author: "Geek"
Information:
Name: "Jim"
Age: 18
cat main.go
package main
import (
"fmt"
"github.com/spf13/viper"
)
func main() {
v := viper.New()
// 设置配置文件的名字为config
v.SetConfigName("config")
// 设置配置文件类型
v.SetConfigType("yaml")<