middleware_hook_template.go 698 B

12345678910111213141516171819202122232425262728293031323334353637
  1. package got
  2. import (
  3. "text/template"
  4. . "git.eugeniocarvalho.dev/eugeniucarvalho/apicodegen/common"
  5. )
  6. var (
  7. hookStmtsTmpl *template.Template
  8. hookStmtsErr error
  9. )
  10. func init() {
  11. hookStmtsTmpl, hookStmtsErr = ParseTemplate(`
  12. import(
  13. {{range $label, $path := .imports}}
  14. {{$label}} "{{$path}}"
  15. {{end}}
  16. )
  17. {{if .hasContext}}
  18. func {{.function}}(options map[string]interface{}) func( context.Context) (interface{},*errs.Error) {
  19. return func(ctx context.Context) (resp interface{}, err *errs.Error) {
  20. return
  21. }
  22. }
  23. {{else}}
  24. func {{.function}}(ctx context.Context) (resp interface{}, err *errs.Error) {
  25. return
  26. }
  27. {{end}}
  28. `)
  29. if hookStmtsErr != nil {
  30. panic(hookStmtsErr)
  31. }
  32. }