mirror of
https://github.com/go-admin-team/go-admin.git
synced 2026-10-04 14:23:48 +00:00
Every import of the module changes, not only the seven packages that
moved out of sdk/pkg: Go requires the major version in the path from v2
on. Both happen in one pass —
go run github.com/go-admin-team/go-admin-core/tools/coreupgrade@v2.0.0 -w -v2 .
go mod tidy
— which is the command the release notes give, run here as a consumer
would run it. 210 imports across 95 files.
The compatibility shims this used are gone in v2, so the paths that
moved had to move: sdk/pkg/captcha, sdk/pkg/jwtauth and its user
package, sdk/pkg/response and sdk/pkg/casbin.
The count of unformatted files is unchanged at 34, none of them touched
by this: the tool reformats a file only if it was already gofmt clean,
so a migration cannot disappear into whitespace.
107 lines
1.9 KiB
Go
107 lines
1.9 KiB
Go
package dto
|
|
|
|
import (
|
|
vd "github.com/bytedance/go-tagexpr/v2/validator"
|
|
"net/http"
|
|
|
|
"github.com/gin-gonic/gin"
|
|
"github.com/go-admin-team/go-admin-core/v2/sdk/api"
|
|
)
|
|
|
|
type ObjectById struct {
|
|
Id int `uri:"id"`
|
|
Ids []int `json:"ids"`
|
|
}
|
|
|
|
func (s *ObjectById) Bind(ctx *gin.Context) error {
|
|
var err error
|
|
log := api.GetRequestLogger(ctx)
|
|
err = ctx.ShouldBindUri(s)
|
|
if err != nil {
|
|
log.Warnf("ShouldBindUri error: %s", err.Error())
|
|
return err
|
|
}
|
|
if ctx.Request.Method == http.MethodDelete {
|
|
err = ctx.ShouldBind(&s)
|
|
if err != nil {
|
|
log.Warnf("ShouldBind error: %s", err.Error())
|
|
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)
|
|
}
|
|
}
|
|
if err = vd.Validate(s); err != nil {
|
|
log.Errorf("Validate error: %s", err.Error())
|
|
return err
|
|
}
|
|
return err
|
|
}
|
|
|
|
func (s *ObjectById) GetId() interface{} {
|
|
if len(s.Ids) > 0 {
|
|
s.Ids = append(s.Ids, s.Id)
|
|
return s.Ids
|
|
}
|
|
return s.Id
|
|
}
|
|
|
|
type ObjectGetReq struct {
|
|
Id int `uri:"id"`
|
|
}
|
|
|
|
func (s *ObjectGetReq) Bind(ctx *gin.Context) error {
|
|
var err error
|
|
log := api.GetRequestLogger(ctx)
|
|
err = ctx.ShouldBindUri(s)
|
|
if err != nil {
|
|
log.Warnf("ShouldBindUri error: %s", err.Error())
|
|
return err
|
|
}
|
|
if err = vd.Validate(s); err != nil {
|
|
log.Errorf("Validate error: %s", err.Error())
|
|
return err
|
|
}
|
|
return err
|
|
}
|
|
|
|
func (s *ObjectGetReq) GetId() interface{} {
|
|
return s.Id
|
|
}
|
|
|
|
type ObjectDeleteReq struct {
|
|
Ids []int `json:"ids"`
|
|
}
|
|
|
|
func (s *ObjectDeleteReq) Bind(ctx *gin.Context) error {
|
|
var err error
|
|
log := api.GetRequestLogger(ctx)
|
|
err = ctx.ShouldBind(&s)
|
|
if err != nil {
|
|
log.Warnf("ShouldBind error: %s", err.Error())
|
|
return err
|
|
}
|
|
if len(s.Ids) > 0 {
|
|
return nil
|
|
}
|
|
if s.Ids == nil {
|
|
s.Ids = make([]int, 0)
|
|
}
|
|
|
|
if err = vd.Validate(s); err != nil {
|
|
log.Errorf("Validate error: %s", err.Error())
|
|
return err
|
|
}
|
|
return err
|
|
}
|
|
|
|
func (s *ObjectDeleteReq) GetId() interface{} {
|
|
return s.Ids
|
|
}
|