i_application.go 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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. Partition int32 `yaml:"partition"`
  35. Broker string `yaml:"broker"`
  36. }
  37. type OssStruct struct {
  38. Type string `yaml:"type"`
  39. IsUseCname bool `yaml:"is-use-cname"`
  40. Endpoint string `yaml:"endpoint"`
  41. AccessKeyId string `yaml:"access-key-id"`
  42. AccessKeySecret string `yaml:"access-key-secret"`
  43. BucketName string `yaml:"bucket-name"`
  44. }
  45. type GpuNode struct {
  46. Hostname string `yaml:"hostname"`
  47. Ip string `yaml:"ip"`
  48. Parallelism int64 `yaml:"parallelism"`
  49. }
  50. type K8sStruct struct {
  51. PodYamlDir string `yaml:"pod-yaml-dir"`
  52. VtdPodTemplateYaml string `yaml:"vtd-pod-template-yaml"`
  53. AlgorithmTarTempDir string `yaml:"algorithm-tar-temp-dir"`
  54. RegistryUri string `yaml:"registry-uri"`
  55. NamespaceName string `yaml:"namespace-name"`
  56. VtdImage string `yaml:"vtd-image"`
  57. VtdCommand string `yaml:"vtd-command"`
  58. }
  59. var (
  60. //go:embed application.yaml
  61. applicationYamlBytes []byte
  62. ApplicationYaml ApplicationYamlStruct
  63. )
  64. func InitApplication() {
  65. _ = yaml.Unmarshal(applicationYamlBytes, &ApplicationYaml)
  66. fmt.Println("加载配置文件内容为:", ApplicationYaml)
  67. }