server.go 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. package config
  2. import (
  3. "encoding/json"
  4. "fmt"
  5. "github.com/go-admin-team/go-admin-core/config/source/file"
  6. "github.com/spf13/cobra"
  7. "github.com/go-admin-team/go-admin-core/sdk/config"
  8. )
  9. var (
  10. configYml string
  11. StartCmd = &cobra.Command{
  12. Use: "config",
  13. Short: "Get Application config info",
  14. Example: "go-admin config -c config/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. // todo 需要兼容
  36. database, errs := json.MarshalIndent(config.DatabasesConfig, "", " ") //转换成JSON返回的是byte[]
  37. if errs != nil {
  38. fmt.Println(errs.Error())
  39. }
  40. fmt.Println("database:", string(database))
  41. gen, errs := json.MarshalIndent(config.GenConfig, "", " ") //转换成JSON返回的是byte[]
  42. if errs != nil {
  43. fmt.Println(errs.Error())
  44. }
  45. fmt.Println("gen:", string(gen))
  46. loggerConfig, errs := json.MarshalIndent(config.LoggerConfig, "", " ") //转换成JSON返回的是byte[]
  47. if errs != nil {
  48. fmt.Println(errs.Error())
  49. }
  50. fmt.Println("logger:", string(loggerConfig))
  51. }