Files
go-admin/common/dto/generate.go
T
2021-02-22 22:00:34 +08:00

44 lines
638 B
Go

package dto
import (
"net/http"
"github.com/gin-gonic/gin"
)
type ObjectById struct {
Id int `uri:"id"`
Ids []int `json:"ids"`
}
func (s *ObjectById) Bind(ctx *gin.Context) error {
var err error
err = ctx.ShouldBindUri(s)
if err != nil {
return err
}
if ctx.Request.Method == http.MethodDelete {
err = ctx.ShouldBind(&s.Ids)
if err != nil {
return err
}
if len(s.Ids) > 0 {
return nil
}
if s.Ids == nil {
s.Ids = make([]int, 0)
}
if s.Id != 0 {
s.Ids = append(s.Ids, s.Id)
}
}
return err
}
func (s *ObjectById) GetId() interface{} {
if len(s.Ids) > 0 {
return s.Ids
}
return s.Id
}