pass_through.go 1.0 KB

12345678910111213141516171819202122232425262728293031
  1. package gateway
  2. import (
  3. "git.sxidc.com/go-framework/baize/framework/binding"
  4. "git.sxidc.com/go-framework/baize/framework/binding/request"
  5. "git.sxidc.com/go-framework/baize/framework/binding/response"
  6. "git.sxidc.com/go-framework/baize/framework/core/api"
  7. "git.sxidc.com/go-framework/baize/framework/core/domain"
  8. "git.sxidc.com/go-framework/baize/framework/core/infrastructure"
  9. "net/http"
  10. )
  11. type PassThrough struct {
  12. HttpMethod string
  13. RelativePath string
  14. ToUrl string
  15. }
  16. func (gw *Gateway) BindPassThrough(binder *binding.Binder, passThrough *PassThrough, middlewares ...api.Handler) {
  17. binding.Bind[any](binder, &binding.BindItem[any]{
  18. Method: passThrough.HttpMethod,
  19. SimpleBindItem: &binding.SimpleBindItem[any]{
  20. Path: passThrough.RelativePath,
  21. ResponseFunc: response.NoResponse,
  22. ServiceFunc: func(c *api.Context, params request.Params, objects []domain.Object, i *infrastructure.Infrastructure) (any, error) {
  23. c.Redirect(http.StatusTemporaryRedirect, passThrough.ToUrl)
  24. return nil, nil
  25. },
  26. },
  27. }, middlewares...)
  28. }