mirror of
https://gitee.com/dromara/mayfly-go
synced 2025-11-03 16:00:25 +08:00
简单基于DDD重构,并实现机器文件及脚本管理
This commit is contained in:
@@ -12,8 +12,14 @@ import (
|
||||
|
||||
// 绑定并校验请求结构体参数
|
||||
func BindJsonAndValid(g *gin.Context, data interface{}) {
|
||||
err := g.BindJSON(data)
|
||||
if err != nil {
|
||||
if err := g.BindJSON(data); err != nil {
|
||||
panic(biz.NewBizErr(err.Error()))
|
||||
}
|
||||
}
|
||||
|
||||
// 绑定查询字符串到
|
||||
func BindQuery(g *gin.Context, data interface{}) {
|
||||
if err := g.BindQuery(data); err != nil {
|
||||
panic(biz.NewBizErr(err.Error()))
|
||||
}
|
||||
}
|
||||
@@ -30,10 +36,17 @@ func QueryInt(g *gin.Context, qm string, defaultInt int) int {
|
||||
return defaultInt
|
||||
}
|
||||
qvi, err := strconv.Atoi(qv)
|
||||
biz.BizErrIsNil(err, "query param not int")
|
||||
biz.ErrIsNil(err, "query param not int")
|
||||
return qvi
|
||||
}
|
||||
|
||||
// 文件下载
|
||||
func Download(g *gin.Context, data []byte, filename string) {
|
||||
g.Header("Content-Type", "application/octet-stream")
|
||||
g.Header("Content-Disposition", "attachment; filename="+filename)
|
||||
g.Data(http.StatusOK, "application/octet-stream", data)
|
||||
}
|
||||
|
||||
// 返回统一成功结果
|
||||
func SuccessRes(g *gin.Context, data interface{}) {
|
||||
g.JSON(http.StatusOK, model.Success(data))
|
||||
|
||||
Reference in New Issue
Block a user