package main /* 1. 算法清理可以用仿真云平台的调度系统 */ import ( "cicv-data-closedloop/amd64/dispatch_server/package/handler" "cicv-data-closedloop/amd64/dispatch_server/package/infra" commonHandler "cicv-data-closedloop/common/gin/handler" "cicv-data-closedloop/common/util" _ "embed" "fmt" "github.com/gin-gonic/gin" "gopkg.in/yaml.v3" "os" ) type ApplicationYamlStruct struct { ApplicationName string `yaml:"application-name"` Web WebStruct `yaml:"web"` Log LogStruct `yaml:"log"` Redis RedisStruct `yaml:"redis"` Oss OssStruct `yaml:"oss"` GpuNodeList []GpuNode `yaml:"gpu_node_list"` } type WebStruct struct { Port string `yaml:"port"` RoutePrefix string `yaml:"route-prefix"` Token string `yaml:"token"` WhiteList []string `yaml:"white-list"` } type LogStruct struct { Dir string `yaml:"dir"` Prefix string `yaml:"prefix"` } type RedisStruct struct { Addr string `yaml:"addr"` Password string `yaml:"password"` Db int `yaml:"db"` } type OssStruct struct { IsUseCname bool `yaml:"is-use-cname"` Endpoint string `yaml:"endpoint"` AccessKeyId string `yaml:"access-key-id"` AccessKeySecret string `yaml:"access-key-secret"` BucketName string `yaml:"bucket-name"` } type GpuNode struct { Hostname string `yaml:"hostname"` Ip string `yaml:"ip"` Parallelism string `yaml:"parallelism"` } var ( //go:embed application.yaml applicationYamlBytes []byte ApplicationYaml ApplicationYamlStruct ) func init() { // 1 解析YAML内容 _ = yaml.Unmarshal(applicationYamlBytes, &ApplicationYaml) fmt.Println("加载配置文件内容为:", ApplicationYaml) // 2 初始化 日志 infra.InitLog(ApplicationYaml.Log.Dir, ApplicationYaml.Log.Prefix) // 3 初始化 阿里云oss 客户端 infra.InitOss( ApplicationYaml.Oss.IsUseCname, ApplicationYaml.Oss.Endpoint, ApplicationYaml.Oss.AccessKeyId, ApplicationYaml.Oss.AccessKeySecret, ApplicationYaml.Oss.BucketName, ) // 4 初始化 Redis 客户端 infra.InitRedisClient( ApplicationYaml.Redis.Addr, ApplicationYaml.Redis.Password, ApplicationYaml.Redis.Db, ) } func main() { router := gin.Default() router.Use(commonHandler.ValidateHeaders()) api := router.Group(ApplicationYaml.Web.RoutePrefix) api.POST("/start-project", handler.StartProject) err := router.Run(":" + ApplicationYaml.Web.Port) if err != nil { infra.GlobalLogger.Error("程序崩溃,监听端口 " + util.ToString(ApplicationYaml.Web.Port) + " 失败。") os.Exit(-1) } }