修复指针问题,提取by_id到公共结构体
This commit is contained in:
1 parent
3bd3656d15
commit
0c64d8b927
5 files changed
+43
-26
No files matched your search
@@ -0,0 +1,38 @@
|
||||
package dto
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"github.com/gin-gonic/gin"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
type ObjectById struct {
|
||||
Id int `uri:"id" validate:"required"`
|
||||
Ids []json.Number `json:"ids"`
|
||||
}
|
||||
|
||||
func (s *ObjectById) Bind(ctx *gin.Context) error {
|
||||
if ctx.Request.Method == http.MethodDelete {
|
||||
err := ctx.Bind(s)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if len(s.Ids) > 0 {
|
||||
return nil
|
||||
}
|
||||
}
|
||||
return ctx.BindUri(s)
|
||||
}
|
||||
|
||||
func (s *ObjectById) GetId() interface{} {
|
||||
if len(s.Ids) > 0 {
|
||||
ids := make([]int64, 0)
|
||||
var i int64
|
||||
for _, id := range s.Ids {
|
||||
i, _ = id.Int64()
|
||||
ids = append(ids, i)
|
||||
}
|
||||
return ids
|
||||
}
|
||||
return s.Id
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
package dto
|
||||
|
||||
type Pagination struct {
|
||||
PageIndex int `form:"pageIndex"`
|
||||
PageSize int `form:"pageSize"`
|
||||
}
|
||||
Reference in new issue
Block a user