标签:cap 图片 pos pack %s market post main yaml
这个可以常常和cobra配合。
来个demo
package main import ( "fmt" "github.com/spf13/viper" ) func main() { v := viper.New() v.SetConfigName("linux_config") v.AddConfigPath("./config/") v.AddConfigPath("%GOPATH/src/") v.SetConfigType("yaml") if err := v.ReadInConfig(); err != nil { fmt.Print("err: %s\n", err) } fmt.Printf( ` TimeStamp:%s CompanyInfomation.Name:%s CompanyInfomation.Department:%s `, v.Get("TimeStamp"), v.Get("CompanyInfomation.Name"), v.Get("CompanyInfomation.Department"), ) }
Linux_config.yaml
TimeStamp: "2018-10-18 10:09:23"
Address: "Shenzhen"
Postcode: 518000
CompanyInfomation:
Name: "Sunny"
MarketCapitalization: 50000000
EmployeeNum: 200
Department:
- "Finance"
- "Design"
- "Program"
- "Sales"
标签:cap 图片 pos pack %s market post main yaml
原文地址:https://www.cnblogs.com/aguncn/p/11747143.html