i_application.go 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. package infra
  2. import (
  3. _ "embed"
  4. "fmt"
  5. "gopkg.in/yaml.v2"
  6. )
  7. type ApplicationYamlStruct struct {
  8. ApplicationName string `yaml:"application-name"`
  9. Web WebStruct `yaml:"web"`
  10. Log LogStruct `yaml:"log"`
  11. Redis RedisStruct `yaml:"redis"`
  12. Kafka KafkaStruct `yaml:"kafka"`
  13. Oss OssStruct `yaml:"oss"`
  14. GpuNodeList []GpuNode `yaml:"gpu-node-list"`
  15. K8s K8sStruct `yaml:"k8s"`
  16. }
  17. type WebStruct struct {
  18. IpPrivate string `yaml:"ip-private"`
  19. Port string `yaml:"port"`
  20. RoutePrefix string `yaml:"route-prefix"`
  21. Token string `yaml:"token"`
  22. WhiteList []string `yaml:"white-list"`
  23. }
  24. type LogStruct struct {
  25. Dir string `yaml:"dir"`
  26. Prefix string `yaml:"prefix"`
  27. }
  28. type RedisStruct struct {
  29. Addr string `yaml:"addr"`
  30. Password string `yaml:"password"`
  31. Db int `yaml:"db"`
  32. }
  33. type KafkaStruct struct {
  34. Brokers []string `yaml:"brokers"`
  35. }
  36. type OssStruct struct {
  37. IsUseCname bool `yaml:"is-use-cname"`
  38. Endpoint string `yaml:"endpoint"`
  39. AccessKeyId string `yaml:"access-key-id"`
  40. AccessKeySecret string `yaml:"access-key-secret"`
  41. BucketName string `yaml:"bucket-name"`
  42. }
  43. type GpuNode struct {
  44. Hostname string `yaml:"hostname"`
  45. Ip string `yaml:"ip"`
  46. Parallelism int64 `yaml:"parallelism"`
  47. }
  48. type K8sStruct struct {
  49. PodYamlDir string `yaml:"pod-yaml-dir"`
  50. VtdPodTemplateYaml string `yaml:"vtd-pod-template-yaml"`
  51. }
  52. var (
  53. //go:embed application.yaml
  54. applicationYamlBytes []byte
  55. ApplicationYaml ApplicationYamlStruct
  56. )
  57. func InitApplication() {
  58. _ = yaml.Unmarshal(applicationYamlBytes, &ApplicationYaml)
  59. fmt.Println("加载配置文件内容为:", ApplicationYaml)
  60. }