server.go 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. package config
  2. import (
  3. "encoding/json"
  4. "fmt"
  5. "github.com/spf13/cobra"
  6. "gogs.baozhida.cn/zoie/OAuth-core/config/source/file"
  7. "gogs.baozhida.cn/zoie/OAuth-core/sdk/config"
  8. )
  9. var (
  10. configYml string
  11. StartCmd = &cobra.Command{
  12. Use: "config",
  13. Short: "Get Application config info",
  14. Example: "gas-cylinder-api config -c conf/settings.yml",
  15. Run: func(cmd *cobra.Command, args []string) {
  16. run()
  17. },
  18. }
  19. )
  20. func init() {
  21. StartCmd.PersistentFlags().StringVarP(&configYml, "config", "c", "config/settings.yml", "Start server with provided configuration file")
  22. }
  23. func run() {
  24. config.Setup(file.NewSource(file.WithPath(configYml)))
  25. application, errs := json.MarshalIndent(config.ApplicationConfig, "", " ") //转换成JSON返回的是byte[]
  26. if errs != nil {
  27. fmt.Println(errs.Error())
  28. }
  29. fmt.Println("application:", string(application))
  30. jwt, errs := json.MarshalIndent(config.JwtConfig, "", " ") //转换成JSON返回的是byte[]
  31. if errs != nil {
  32. fmt.Println(errs.Error())
  33. }
  34. fmt.Println("jwt:", string(jwt))
  35. database, errs := json.MarshalIndent(config.DatabasesConfig, "", " ") //转换成JSON返回的是byte[]
  36. if errs != nil {
  37. fmt.Println(errs.Error())
  38. }
  39. fmt.Println("database:", string(database))
  40. gen, errs := json.MarshalIndent(config.GenConfig, "", " ") //转换成JSON返回的是byte[]
  41. if errs != nil {
  42. fmt.Println(errs.Error())
  43. }
  44. fmt.Println("gen:", string(gen))
  45. loggerConfig, errs := json.MarshalIndent(config.LoggerConfig, "", " ") //转换成JSON返回的是byte[]
  46. if errs != nil {
  47. fmt.Println(errs.Error())
  48. }
  49. fmt.Println("logger:", string(loggerConfig))
  50. }