middleware_filter.go 627 B

1234567891011121314151617181920212223242526272829303132333435
  1. package got
  2. import (
  3. "fmt"
  4. "strings"
  5. . "git.eugeniocarvalho.dev/eugeniucarvalho/apicodegen/common"
  6. G "github.com/dave/jennifer/jen"
  7. )
  8. var (
  9. GenGetFilter = &Middleware{
  10. Id: "filter",
  11. Type: "method",
  12. Fn: func(ctx *MiddlewareContext) error {
  13. var (
  14. method = ctx.Method
  15. entity = strings.ToLower(method.Entity)
  16. )
  17. ctx.Statement.Block(G.Id(`
  18. var (
  19. ok bool
  20. res *`).
  21. Qual(CODE_GEN_V2_COMMON, "ApiFilter").
  22. Id(fmt.Sprintf(`
  23. )
  24. if res, ok = filtersApiReference["%s"]; !ok {
  25. res = common.NewApiFilter("%s")
  26. }
  27. return res, nil
  28. `, entity, entity)))
  29. return nil
  30. },
  31. }
  32. )