main.go 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. // Copyright 2025 BackendServerTemplate Authors. All rights reserved.
  2. // Use of this source code is governed by a MIT-style
  3. // license that can be found in the LICENSE file.
  4. package v1
  5. import (
  6. "fmt"
  7. "github.com/SongZihuan/BackendServerTemplate/src/config"
  8. "github.com/SongZihuan/BackendServerTemplate/src/config/configparser"
  9. "github.com/SongZihuan/BackendServerTemplate/src/utils/exitutils"
  10. "github.com/spf13/cobra"
  11. )
  12. var InputConfigFilePath string = "config.yaml"
  13. var OutputConfigFilePath string = ""
  14. func MainV1(cmd *cobra.Command, args []string) (exitCode error) {
  15. var err error
  16. configProvider, err := configparser.NewProvider(InputConfigFilePath, &configparser.NewProviderOption{
  17. AutoReload: false,
  18. })
  19. if err != nil {
  20. return exitutils.SuccessExitSimple(fmt.Sprintf("Error: config file check failed: %s!", err.Error()))
  21. }
  22. err = config.InitConfig(&config.ConfigOption{
  23. ConfigFilePath: InputConfigFilePath,
  24. OutputFilePath: OutputConfigFilePath,
  25. Provider: configProvider,
  26. })
  27. if err != nil {
  28. return exitutils.SuccessExitSimple(fmt.Sprintf("Error: config file check failed: %s!", err.Error()))
  29. }
  30. return exitutils.SuccessExitSimple("Info: config file check ok!")
  31. }