You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

38 lines
1002 B

package main
import (
"fmt"
"github.com/spf13/viper"
)
// 失败!
func main() {
v := viper.New()
v.SetConfigFile("config.yaml")
v.SetConfigType("yaml")
if err := v.ReadInConfig(); err != nil {
fmt.Println(err)
return
}
fmt.Println(v.GetString("web.static_path"))
fmt.Println(v.GetString("web.domain"))
fmt.Println(v.GetInt("web.port"))
fmt.Println(v.GetInt("web.read_timeout"))
fmt.Println(v.GetInt("web.write_timeout"))
fmt.Println(v.GetInt("web.idle_timeout"))
fmt.Println(v.GetString("mysql.host"))
fmt.Println(v.GetInt("mysql.port"))
fmt.Println(v.GetString("mysql.user"))
fmt.Println(v.GetString("mysql.password"))
fmt.Println(v.GetString("mysql.db_name"))
fmt.Println(v.GetString("mysql.parameters"))
fmt.Println(v.GetBool("gorm.debug"))
fmt.Println(v.GetString("gorm.db_type"))
fmt.Println(v.GetInt("gorm.max_lifetime"))
fmt.Println(v.GetInt("gorm.max_open_conns"))
fmt.Println(v.GetInt("gorm.max_idle_conns"))
fmt.Println(v.GetString("gorm.table_prefix"))
}