package binding_context import ( "git.sxidc.com/service-supports/fserr" "git.sxidc.com/service-supports/fslog" "github.com/gin-gonic/gin" "io" "lcp/errcode" "lcp/utils" "mime/multipart" ) type Context struct { *gin.Context } func (c *Context) GetPathParams(pathParamNames []string) ([]string, error) { pathParamValues := make([]string, 0) for _, paramName := range pathParamNames { paramValue := c.Param(paramName) if utils.IsStringEmpty(paramValue) { return nil, fserr.WithCode(nil, errcode.ErrCommon, fserr.MsgOption("没有传递路径参数"+paramName)) } pathParamValues = append(pathParamValues, paramValue) } return pathParamValues, nil } func (c *Context) GetFileHeaderBytes(fileHeader *multipart.FileHeader) (string, []byte, error) { file, err := fileHeader.Open() if err != nil { return "", nil, err } defer func(file multipart.File) { err := file.Close() if err != nil { fslog.Error(err) return } }(file) contentBytes, err := io.ReadAll(file) if err != nil { return "", nil, err } return fileHeader.Filename, contentBytes, nil }