i_application.go 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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. AlgorithmTarTempDir string `yaml:"algorithm-tar-temp-dir"`
  52. RegistryUri string `yaml:"registry-uri"`
  53. }
  54. var (
  55. //go:embed application.yaml
  56. applicationYamlBytes []byte
  57. ApplicationYaml ApplicationYamlStruct
  58. )
  59. func InitApplication() {
  60. _ = yaml.Unmarshal(applicationYamlBytes, &ApplicationYaml)
  61. fmt.Println("加载配置文件内容为:", ApplicationYaml)
  62. }