parent
8758733bc9
commit
6507272923
@ -0,0 +1,43 @@
|
||||
package ai_recognition
|
||||
|
||||
import (
|
||||
"encoding/base64"
|
||||
"goskeleton/app/global/consts"
|
||||
"goskeleton/app/http/controller/web"
|
||||
"goskeleton/app/http/validator/core/data_transfer"
|
||||
"goskeleton/app/utils/response"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
type VocRecognition struct {
|
||||
Voc string `form:"voc" json:"voc" binding:"required"` // 必填、对于文本,表示它的长度>=1
|
||||
}
|
||||
|
||||
func (v VocRecognition) CheckParams(context *gin.Context) {
|
||||
if err := context.ShouldBind(&v); err != nil {
|
||||
// 将表单参数验证器出现的错误直接交给错误翻译器统一处理即可
|
||||
response.ValidatorError(context, err)
|
||||
return
|
||||
}
|
||||
// 该函数主要是将本结构体的字段(成员)按照 consts.ValidatorPrefix+ json标签对应的 键 => 值 形式绑定在上下文,便于下一步(控制器)可以直接通过 context.Get(键) 获取相关值
|
||||
extraAddBindDataContext := data_transfer.DataAddContext(v, consts.ValidatorPrefix, context)
|
||||
if extraAddBindDataContext == nil {
|
||||
response.ErrorSystem(context, "VocRecognition表单参数验证器json化失败", "")
|
||||
return
|
||||
}
|
||||
voc := v.Voc
|
||||
// 先进行 URL 解码
|
||||
// decodedVoc, err := url.QueryUnescape(voc)
|
||||
// if err != nil {
|
||||
// response.ErrorSystem(context, "VocRecognition表单参数验证器URL解码失败", "")
|
||||
// return
|
||||
// }
|
||||
// 再进行 Base64 解码
|
||||
_, err := base64.StdEncoding.DecodeString(voc)
|
||||
if err != nil {
|
||||
response.ErrorSystem(context, "VocRecognition表单参数验证器Base64解码失败", "")
|
||||
return
|
||||
}
|
||||
(&web.AiRecognition{}).VocRecognition(extraAddBindDataContext)
|
||||
}
|
File diff suppressed because one or more lines are too long
Binary file not shown.
File diff suppressed because one or more lines are too long
Loading…
Reference in new issue