generate.go 461 B

1234567891011121314151617181920212223242526272829303132
  1. package dto
  2. import (
  3. "net/http"
  4. "github.com/gin-gonic/gin"
  5. )
  6. type ObjectById struct {
  7. Id int `uri:"id"`
  8. Ids []int `json:"ids"`
  9. }
  10. func (s *ObjectById) Bind(ctx *gin.Context) error {
  11. if ctx.Request.Method == http.MethodDelete {
  12. err := ctx.Bind(s)
  13. if err != nil {
  14. return err
  15. }
  16. if len(s.Ids) > 0 {
  17. return nil
  18. }
  19. }
  20. return ctx.BindUri(s)
  21. }
  22. func (s *ObjectById) GetId() interface{} {
  23. if len(s.Ids) > 0 {
  24. return s.Ids
  25. }
  26. return s.Id
  27. }