config.go 895 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. package config
  2. import (
  3. "fmt"
  4. "os"
  5. "git.sxidc.com/go-framework/baize/framework/core/application"
  6. "gopkg.in/yaml.v3"
  7. )
  8. type servicesConfig struct {
  9. TimeoutSec int64 `yaml:"timeout_sec"`
  10. UMBaseUrl string `yaml:"um_base_url"`
  11. TMBaseUrl string `yaml:"tm_base_url"`
  12. }
  13. type GatewayConfig struct {
  14. ApplicationConfig application.Config
  15. ServicesConfig servicesConfig `yaml:"services"`
  16. }
  17. var conf = &GatewayConfig{}
  18. func init() {
  19. configFilePath := os.Getenv("CONFIG_FILE_PATH")
  20. applicationConfig, err := application.LoadFromYamlFile(configFilePath)
  21. if err != nil {
  22. panic(err)
  23. }
  24. conf.ApplicationConfig = applicationConfig
  25. yamlBytes, err := os.ReadFile(configFilePath)
  26. if err != nil {
  27. panic(err)
  28. }
  29. err = yaml.Unmarshal(yamlBytes, &conf)
  30. if err != nil {
  31. panic(err)
  32. }
  33. fmt.Println("Load config file finish")
  34. }
  35. func GetGatewayConfig() *GatewayConfig {
  36. return conf
  37. }