i_application.go 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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. Oss OssStruct `yaml:"oss"`
  13. GpuNodeList []GpuNode `yaml:"gpu-node-list"`
  14. K8s K8sStruct `yaml:"k8s"`
  15. }
  16. type WebStruct struct {
  17. IpPrivate string `yaml:"ip-private"`
  18. Port string `yaml:"port"`
  19. RoutePrefix string `yaml:"route-prefix"`
  20. Token string `yaml:"token"`
  21. WhiteList []string `yaml:"white-list"`
  22. }
  23. type LogStruct struct {
  24. Dir string `yaml:"dir"`
  25. Prefix string `yaml:"prefix"`
  26. }
  27. type RedisStruct struct {
  28. Addr string `yaml:"addr"`
  29. Password string `yaml:"password"`
  30. Db int `yaml:"db"`
  31. }
  32. type OssStruct struct {
  33. IsUseCname bool `yaml:"is-use-cname"`
  34. Endpoint string `yaml:"endpoint"`
  35. AccessKeyId string `yaml:"access-key-id"`
  36. AccessKeySecret string `yaml:"access-key-secret"`
  37. BucketName string `yaml:"bucket-name"`
  38. }
  39. type GpuNode struct {
  40. Hostname string `yaml:"hostname"`
  41. Ip string `yaml:"ip"`
  42. Parallelism int64 `yaml:"parallelism"`
  43. }
  44. type K8sStruct struct {
  45. PodYamlDir string `yaml:"pod-yaml-dir"`
  46. VtdPodTemplateYaml string `yaml:"vtd-pod-template-yaml"`
  47. }
  48. var (
  49. //go:embed application.yaml
  50. applicationYamlBytes []byte
  51. ApplicationYaml ApplicationYamlStruct
  52. )
  53. func InitApplication() {
  54. _ = yaml.Unmarshal(applicationYamlBytes, &ApplicationYaml)
  55. fmt.Println("加载配置文件内容为:", ApplicationYaml)
  56. }