554325746@qq.com
2019-12-23 0222e79afe45d9fc55aed9a7e62ca239c228ab73
controllers/sdk.go
@@ -2,9 +2,13 @@
import (
   "basic.com/dbapi.git"
   uuid "github.com/satori/go.uuid"
   "webserver/extend/code"
   "webserver/extend/config"
   "basic.com/valib/logger.git"
   "webserver/extend/util"
   "github.com/gin-gonic/gin"
   "webserver/service"
)
type SdkController struct {
@@ -30,12 +34,16 @@
   Name  string `json:"name"`  //参数名称
   Type  string `json:"type"`  //参数类型(整数,字符串或数组)
   Must  bool   `json:"must"`  //是否必填
   Unit  string `json:"unit"`
   Range string `json:"range"` //值的范围,eg:0,100表示从0到100
   DefaultValue string `json:"default_value"`
   Sort  int    `json:"sort"`  //参数顺序
}
// @Security ApiKeyAuth
// @Summary 算法保存
// @Description 算法保存
// @Accept json
// @Produce json
// @Tags sdk
// @Param reqMap body controllers.SdkVo true "人脸检测"
@@ -59,6 +67,7 @@
   }
}
// @Security ApiKeyAuth
// @Summary 查找所有算法
// @Description 查找所有算法
// @Produce json
@@ -75,6 +84,7 @@
   util.ResponseFormat(c, code.Success, sdks)
}
// @Security ApiKeyAuth
// @Summary 根据id获取算法信息
// @Description 根据id获取算法信息
// @Produce json
@@ -100,6 +110,24 @@
   }
}
// @Router /data/api-v/sdkArg/getSdkArgs [get]
func (sc SdkController) GetSdkArgs(c *gin.Context) {
   sdkId := c.Query("sdkId")
   scope := c.Query("scope")
   if sdkId== "" || scope == ""{
      util.ResponseFormat(c,code.RequestParamError,"参数有误")
      return
   }
   var api dbapi.SdkApi
   b,d := api.GetSdkArgs(sdkId, scope)
   if b{
      util.ResponseFormat(c,code.Success,d)
   } else {
      util.ResponseFormat(c,code.ComError,"查询失败")
   }
}
// @Security ApiKeyAuth
// @Summary 根据taskId获取算法信息
// @Description 根据taskId获取算法信息
// @Produce json
@@ -121,4 +149,44 @@
   } else {
      util.ResponseFormat(c,code.ComError,sdks)
   }
}
func (sc SdkController) SdkDownLoad(c *gin.Context) {
   path,exist := c.GetQuery("path")
   if !exist {
      util.ResponseFormat(c,code.ComError,"下载的算法参数有误")
   }
   logger.Info(path)
   flag := c.Query("needUpdateMiddle")
   // 下载算法(有时候也需要把中间件一起下载下来)
   if flag == "true" {
      // 下载并更新中间件,带上MD5校验
      flag1,err := service.DownSo("http://"+config.SoPath.Ip+":"+config.SoPath.Port+"/"+"middleware.so")
      logger.Debug("中间件路径:","http://"+config.SoPath.Ip+":"+config.SoPath.Port+"/"+"middleware.so")
      if err != nil {
         logger.Info(err)
      }
      if !flag1 {
         util.ResponseFormat(c,code.ComError,"请重新下载算法")
      }
   }
   // 下载算法,校验,并写入到目标目录下
   flag2,err2 := service.DownSo(path)
   if err2 != nil {
      logger.Info(err2)
   }
   if !flag2 {
      util.ResponseFormat(c,code.ComError,"请重新下载算法")
   }
   // 将算法和so名称存到规则私有的注册表
   var soApi dbapi.SoApi
   param := make(map[string]interface{})
   param["id"] = uuid.NewV4().String()
   sdkId := uuid.NewV4().String()
   param["sdkId"] = sdkId
   param["soName"] = service.GetFileNameFromUrl(path,true)
   flag3,_ := soApi.Add(param)
   if flag3 {
      util.ResponseFormat(c,code.Success,"下载算法成功!")
   }
}