111 lines
3.1 KiB
Go
111 lines
3.1 KiB
Go
package router
|
|
|
|
import (
|
|
"fmt"
|
|
"github.com/gin-gonic/gin"
|
|
"gitlink.org.cn/JointCloud/pcm-octopus/http/apis"
|
|
"regexp"
|
|
"time"
|
|
)
|
|
|
|
func Create() (*gin.Engine, error) {
|
|
g := gin.New()
|
|
|
|
g.Use(gin.LoggerWithFormatter(logFormatter), gin.Recovery())
|
|
g.Use(gin.Logger())
|
|
g.Use(gin.Recovery())
|
|
//g.GET("/swagger/*any", ginSwagger.WrapHandler(swaggerFiles.Handler))
|
|
|
|
api := g.Group("/api")
|
|
v1 := api.Group("/v1")
|
|
{
|
|
//token
|
|
token := v1.Group("token")
|
|
token.POST("", apis.Token)
|
|
|
|
//algorithm
|
|
algorithm := v1.Group("algorithm")
|
|
algorithm.GET("/myAlgorithmList", apis.GetMyAlgorithmList)
|
|
algorithm.GET("/applyList", apis.GetAlgorithmApplyList)
|
|
algorithm.GET("/frameworkList", apis.GetAlgorithmFrameworkList)
|
|
algorithm.GET("/versionList", apis.GetAlgorithmVersionList)
|
|
algorithm.POST("/create", apis.CreateMyAlgorithm)
|
|
algorithm.POST("/upload", apis.UploadMyAlgorithm)
|
|
algorithm.PUT("/uploadConfirm", apis.AlgorithmUploadConfirm)
|
|
|
|
//datasets
|
|
datasets := v1.Group("dataset")
|
|
datasets.GET("/myDatasetList", apis.GetMyDatasetList)
|
|
datasets.GET("/applyList", apis.GetDatasetApplyList)
|
|
datasets.GET("/typeList", apis.GetDatasetTypeList)
|
|
datasets.GET("/versionList", apis.GetDatasetVersionList)
|
|
datasets.POST("/create", apis.CreateDataset)
|
|
datasets.POST("/upload", apis.UploadDataset)
|
|
datasets.PUT("/uploadConfirm", apis.DatasetUploadConfirm)
|
|
|
|
//image
|
|
image := v1.Group("image")
|
|
image.GET("/myImageList", apis.GetMyImageList)
|
|
image.GET("/presetList", apis.GetPresetImageList)
|
|
|
|
//model
|
|
model := v1.Group("model")
|
|
model.GET("/myModelList", apis.GetMyModelList)
|
|
model.GET("/modelVersionList", apis.GetModelVersionList)
|
|
model.GET("/downloadModelVersion", apis.DownloadModelVersion)
|
|
model.GET("/commModelList", apis.GetCommModelList)
|
|
model.GET("/preModelList", apis.GetPreModelList)
|
|
|
|
//platformStatistic
|
|
stat := v1.Group("stat")
|
|
stat.GET("/platformStat", apis.GetPlatformStat)
|
|
|
|
//resource
|
|
resource := v1.Group("resource")
|
|
resource.GET("/specs", apis.GetResourcespecs)
|
|
|
|
//trainjob
|
|
job := v1.Group("job")
|
|
job.POST("/create", apis.CreateTrainJob)
|
|
job.GET("/list", apis.GetTrainJobList)
|
|
job.GET("/detail", apis.TrainJobDetail)
|
|
job.GET("/log", apis.TrainJobLog)
|
|
|
|
//billing
|
|
bill := v1.Group("bill")
|
|
bill.GET("/userBalance", apis.GetUserBalance)
|
|
|
|
}
|
|
|
|
return g, nil
|
|
}
|
|
|
|
var tokenRegexp = regexp.MustCompile("token=[^&]+")
|
|
|
|
func logFormatter(param gin.LogFormatterParams) string {
|
|
if (param.ClientIP == "127.0.0.1" || param.ClientIP == "::1") && param.Path == "/health" {
|
|
return ""
|
|
}
|
|
|
|
var statusColor, methodColor, resetColor string
|
|
if param.IsOutputColor() {
|
|
statusColor = param.StatusCodeColor()
|
|
methodColor = param.MethodColor()
|
|
resetColor = param.ResetColor()
|
|
}
|
|
|
|
if param.Latency > time.Minute {
|
|
param.Latency = param.Latency - param.Latency%time.Second
|
|
}
|
|
path := tokenRegexp.ReplaceAllString(param.Path, "token=[masked]")
|
|
return fmt.Sprintf("%v |%s %3d %s| %13v | %15s |%s %-7s %s %#v\n%s",
|
|
param.TimeStamp.Format(time.RFC3339),
|
|
statusColor, param.StatusCode, resetColor,
|
|
param.Latency,
|
|
param.ClientIP,
|
|
methodColor, param.Method, resetColor,
|
|
path,
|
|
param.ErrorMessage,
|
|
)
|
|
}
|