package config import ( "encoding/json" "fmt" "github.com/spf13/cobra" "gogs.baozhida.cn/zoie/OAuth-core/config/source/file" "gogs.baozhida.cn/zoie/OAuth-core/sdk/config" ) var ( configYml string StartCmd = &cobra.Command{ Use: "config", Short: "Get Application config info", Example: "gas-cylinder-api config -c conf/settings.yml", Run: func(cmd *cobra.Command, args []string) { run() }, } ) func init() { StartCmd.PersistentFlags().StringVarP(&configYml, "config", "c", "config/settings.yml", "Start server with provided configuration file") } func run() { config.Setup(file.NewSource(file.WithPath(configYml))) application, errs := json.MarshalIndent(config.ApplicationConfig, "", " ") //转换成JSON返回的是byte[] if errs != nil { fmt.Println(errs.Error()) } fmt.Println("application:", string(application)) jwt, errs := json.MarshalIndent(config.JwtConfig, "", " ") //转换成JSON返回的是byte[] if errs != nil { fmt.Println(errs.Error()) } fmt.Println("jwt:", string(jwt)) database, errs := json.MarshalIndent(config.DatabasesConfig, "", " ") //转换成JSON返回的是byte[] if errs != nil { fmt.Println(errs.Error()) } fmt.Println("database:", string(database)) gen, errs := json.MarshalIndent(config.GenConfig, "", " ") //转换成JSON返回的是byte[] if errs != nil { fmt.Println(errs.Error()) } fmt.Println("gen:", string(gen)) loggerConfig, errs := json.MarshalIndent(config.LoggerConfig, "", " ") //转换成JSON返回的是byte[] if errs != nil { fmt.Println(errs.Error()) } fmt.Println("logger:", string(loggerConfig)) }