| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364 |
- package gateway
- import (
- "git.sxidc.com/go-framework/baize/framework/binding"
- "git.sxidc.com/go-framework/baize/framework/binding/request"
- "git.sxidc.com/go-framework/baize/framework/binding/response"
- "git.sxidc.com/go-framework/baize/framework/core/api"
- "git.sxidc.com/go-framework/baize/framework/core/domain"
- "git.sxidc.com/go-framework/baize/framework/core/infrastructure"
- "net/http"
- )
- func (gw *Gateway) PostBindPassThrough(binder *binding.Binder, simple *SimplePassThrough, middlewares ...api.Handler) {
- simple.bind(binder, http.MethodPost, middlewares...)
- }
- func (gw *Gateway) DeleteBindPassThrough(binder *binding.Binder, simple *SimplePassThrough, middlewares ...api.Handler) {
- simple.bind(binder, http.MethodDelete, middlewares...)
- }
- func (gw *Gateway) PutBindPassThrough(binder *binding.Binder, simple *SimplePassThrough, middlewares ...api.Handler) {
- simple.bind(binder, http.MethodPost, middlewares...)
- }
- func (gw *Gateway) GetBindPassThrough(binder *binding.Binder, simple *SimplePassThrough, middlewares ...api.Handler) {
- simple.bind(binder, http.MethodGet, middlewares...)
- }
- func (gw *Gateway) BindPassThrough(binder *binding.Binder, passThrough *PassThrough, middlewares ...api.Handler) {
- passThrough.bind(binder, middlewares...)
- }
- type SimplePassThrough struct {
- RelativePath string
- ToUrl string
- }
- func (simple *SimplePassThrough) bind(binder *binding.Binder, httpMethod string, middlewares ...api.Handler) {
- passThrough := &PassThrough{
- HttpMethod: httpMethod,
- SimplePassThrough: simple,
- }
- passThrough.bind(binder, middlewares...)
- }
- type PassThrough struct {
- HttpMethod string
- *SimplePassThrough
- }
- func (passThrough *PassThrough) bind(binder *binding.Binder, middlewares ...api.Handler) {
- binding.Bind[any](binder, &binding.BindItem[any]{
- Method: passThrough.HttpMethod,
- SimpleBindItem: &binding.SimpleBindItem[any]{
- Path: passThrough.RelativePath,
- ResponseFunc: response.NoResponse,
- ServiceFunc: func(c *api.Context, params request.Params, objects []domain.Object, i *infrastructure.Infrastructure) (any, error) {
- c.Redirect(http.StatusTemporaryRedirect, passThrough.ToUrl)
- return nil, nil
- },
- },
- }, middlewares...)
- }
|