main.go 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. package main
  2. /*
  3. 1. 算法清理可以用仿真云平台的调度系统
  4. */
  5. import (
  6. "cicv-data-closedloop/amd64/dispatch_server/package/handler"
  7. "cicv-data-closedloop/amd64/dispatch_server/package/infra"
  8. commonHandler "cicv-data-closedloop/common/gin/handler"
  9. "cicv-data-closedloop/common/util"
  10. _ "embed"
  11. "github.com/gin-gonic/gin"
  12. "gopkg.in/yaml.v3"
  13. "os"
  14. )
  15. type ApplicationYamlStruct struct {
  16. ApplicationName string `yaml:"application"`
  17. Web WebStruct `yaml:"web"`
  18. Redis RedisStruct `yaml:"redis"`
  19. Oss OssStruct `yaml:"oss"`
  20. GpuNodeList []GpuNode `yaml:"gpu_node_list"`
  21. }
  22. type WebStruct struct {
  23. Port string `yaml:"port"`
  24. RoutePrefix string `yaml:"route-prefix"`
  25. Token string `yaml:"token"`
  26. WhiteList []string `yaml:"white-list"`
  27. }
  28. type RedisStruct struct {
  29. Addr string `yaml:"addr"`
  30. Password string `yaml:"password"`
  31. Db int `yaml:"db"`
  32. }
  33. type OssStruct struct {
  34. IsUseCname bool `json:"is-use-cname"`
  35. Endpoint string `json:"endpoint"`
  36. AccessKeyId string `json:"accessKeyId"`
  37. AccessKeySecret string `json:"accessKeySecret"`
  38. BucketName string `json:"bucketName"`
  39. }
  40. type GpuNode struct {
  41. Hostname string `yaml:"hostname"`
  42. Ip string `yaml:"ip"`
  43. Parallelism string `yaml:"parallelism"`
  44. }
  45. var (
  46. //go:embed application.yaml
  47. applicationYamlBytes []byte
  48. ApplicationYaml ApplicationYamlStruct
  49. )
  50. func init() {
  51. // 1 解析YAML内容
  52. _ = yaml.Unmarshal(applicationYamlBytes, &ApplicationYaml)
  53. // 2 初始化 日志
  54. infra.InitLog("./log/", ApplicationYaml.ApplicationName)
  55. // 3 初始化 阿里云oss 客户端
  56. infra.InitOss(
  57. ApplicationYaml.Oss.IsUseCname,
  58. ApplicationYaml.Oss.Endpoint,
  59. ApplicationYaml.Oss.AccessKeyId,
  60. ApplicationYaml.Oss.AccessKeySecret,
  61. ApplicationYaml.Oss.BucketName,
  62. )
  63. // 4 初始化 Redis 客户端
  64. infra.InitRedisClient(
  65. ApplicationYaml.Redis.Addr,
  66. ApplicationYaml.Redis.Password,
  67. ApplicationYaml.Redis.Db,
  68. )
  69. }
  70. func main() {
  71. router := gin.Default()
  72. router.Use(commonHandler.ValidateHeaders())
  73. api := router.Group(ApplicationYaml.Web.RoutePrefix)
  74. api.POST("/start-project", handler.StartProject)
  75. err := router.Run(":" + ApplicationYaml.Web.Port)
  76. if err != nil {
  77. infra.GlobalLogger.Error("程序崩溃,监听端口 " + util.ToString(ApplicationYaml.Web.Port) + " 失败。")
  78. os.Exit(-1)
  79. }
  80. }