From 44a3666d685db72b42e1392351228d7af7b0f2f1 Mon Sep 17 00:00:00 2001 From: eson <9673575+githubcontent@user.noreply.gitee.com> Date: Fri, 21 Jul 2023 11:24:26 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9tpl=E7=9A=84=E5=8F=82?= =?UTF-8?q?=E6=95=B0=E4=BC=A0=E5=85=A5=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- goctl_template/api/handler.tpl | 2 +- goctl_template/api/logic.tpl | 2 +- goctl_template_backend/api/handler.tpl | 2 +- goctl_template_backend/api/logic.tpl | 2 +- server/assistant/internal/handler/redirecthandler.go | 2 +- server/assistant/internal/handler/routes.go | 2 +- .../home-user-auth/internal/logic/usergoogleloginlogic.go | 8 ++++++-- server_api/assistant.api | 2 +- utils/basic/request_parse.go | 4 ++-- 9 files changed, 15 insertions(+), 11 deletions(-) diff --git a/goctl_template/api/handler.tpl b/goctl_template/api/handler.tpl index c7704c2d..1a6b35da 100644 --- a/goctl_template/api/handler.tpl +++ b/goctl_template/api/handler.tpl @@ -26,7 +26,7 @@ func {{.HandlerName}}(svcCtx *svc.ServiceContext) http.HandlerFunc { {{if .HasResp}}resp{{end}} := l.{{.Call}}({{if .HasRequest}}&req, {{end}}userinfo) - if !basic.AfterLogic(w, r, resp, rl) { + if !basic.AfterLogic(w, r, rl) { basic.NormalAfterLogic(w, r, resp) } } diff --git a/goctl_template/api/logic.tpl b/goctl_template/api/logic.tpl index 90690c26..e1504e4e 100644 --- a/goctl_template/api/logic.tpl +++ b/goctl_template/api/logic.tpl @@ -26,7 +26,7 @@ func New{{.logic}}(ctx context.Context, svcCtx *svc.ServiceContext) *{{.logic}} // } // 处理逻辑后 w,r 如:重定向 -// func (l *{{.logic}}) AfterLogic(w http.ResponseWriter, r *http.Request, resp *basic.Response) { +// func (l *{{.logic}}) AfterLogic(w http.ResponseWriter, r *http.Request) { // } func (l *{{.logic}}) {{.function}}({{.request}}, userinfo *auth.UserInfo) (resp *basic.Response) { diff --git a/goctl_template_backend/api/handler.tpl b/goctl_template_backend/api/handler.tpl index 47f0ea3e..ca8330c6 100644 --- a/goctl_template_backend/api/handler.tpl +++ b/goctl_template_backend/api/handler.tpl @@ -25,7 +25,7 @@ func {{.HandlerName}}(svcCtx *svc.ServiceContext) http.HandlerFunc { {{if .HasResp}}resp{{end}} := l.{{.Call}}({{if .HasRequest}}&req, {{end}}userinfo) - if !basic.AfterLogic(w, r, resp, rl) { + if !basic.AfterLogic(w, r, rl) { basic.NormalAfterLogic(w, r, resp) } } diff --git a/goctl_template_backend/api/logic.tpl b/goctl_template_backend/api/logic.tpl index 90690c26..e1504e4e 100644 --- a/goctl_template_backend/api/logic.tpl +++ b/goctl_template_backend/api/logic.tpl @@ -26,7 +26,7 @@ func New{{.logic}}(ctx context.Context, svcCtx *svc.ServiceContext) *{{.logic}} // } // 处理逻辑后 w,r 如:重定向 -// func (l *{{.logic}}) AfterLogic(w http.ResponseWriter, r *http.Request, resp *basic.Response) { +// func (l *{{.logic}}) AfterLogic(w http.ResponseWriter, r *http.Request) { // } func (l *{{.logic}}) {{.function}}({{.request}}, userinfo *auth.UserInfo) (resp *basic.Response) { diff --git a/server/assistant/internal/handler/redirecthandler.go b/server/assistant/internal/handler/redirecthandler.go index 737ec85c..b10d7260 100644 --- a/server/assistant/internal/handler/redirecthandler.go +++ b/server/assistant/internal/handler/redirecthandler.go @@ -28,7 +28,7 @@ func RedirectHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { resp := l.Redirect(&req, userinfo) - if !basic.AfterLogic(w, r, resp, rl) { + if !basic.AfterLogic(w, r, rl) { basic.NormalAfterLogic(w, r, resp) } } diff --git a/server/assistant/internal/handler/routes.go b/server/assistant/internal/handler/routes.go index 4a9dd032..c15a409d 100644 --- a/server/assistant/internal/handler/routes.go +++ b/server/assistant/internal/handler/routes.go @@ -14,7 +14,7 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) { []rest.Route{ { Method: http.MethodGet, - Path: "/api/redirect", + Path: "/api/assistant/redirect", Handler: RedirectHandler(serverCtx), }, }, diff --git a/server/home-user-auth/internal/logic/usergoogleloginlogic.go b/server/home-user-auth/internal/logic/usergoogleloginlogic.go index aac315e7..9427fcb8 100644 --- a/server/home-user-auth/internal/logic/usergoogleloginlogic.go +++ b/server/home-user-auth/internal/logic/usergoogleloginlogic.go @@ -25,6 +25,8 @@ type UserGoogleLoginLogic struct { logx.Logger ctx context.Context svcCtx *svc.ServiceContext + + redirectUrl string } func NewUserGoogleLoginLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UserGoogleLoginLogic { @@ -39,8 +41,10 @@ func (l *UserGoogleLoginLogic) BeforeLogic(w http.ResponseWriter, r *http.Reques log.Println(r, w) } -func (l *UserGoogleLoginLogic) AfterLogic(w http.ResponseWriter, r *http.Request, resp *basic.Response) { - http.Redirect(w, r, "http://localhost:9900/redirect?uri=%s", http.StatusFound) +func (l *UserGoogleLoginLogic) AfterLogic(w http.ResponseWriter, r *http.Request) { + if l.redirectUrl != "" { + http.Redirect(w, r, "http://localhost:9900/assistant/redirect?url="+url.QueryEscape(l.redirectUrl), http.StatusFound) + } } func (l *UserGoogleLoginLogic) UserGoogleLogin(req *types.RequestGoogleLogin, userinfo *auth.UserInfo) (resp *basic.Response) { diff --git a/server_api/assistant.api b/server_api/assistant.api index e3d717c4..e92d6354 100644 --- a/server_api/assistant.api +++ b/server_api/assistant.api @@ -12,5 +12,5 @@ import "basic.api" service assistant { // 处理重定向 @handler RedirectHandler - get /api/redirect(request) returns (response); + get /api/assistant/redirect(request) returns (response); } \ No newline at end of file diff --git a/utils/basic/request_parse.go b/utils/basic/request_parse.go index 4533e64a..cf88b23f 100644 --- a/utils/basic/request_parse.go +++ b/utils/basic/request_parse.go @@ -27,11 +27,11 @@ func BeforeLogic(w http.ResponseWriter, r *http.Request, l reflect.Value) (isNex return true } -func AfterLogic(w http.ResponseWriter, r *http.Request, resp *Response, l reflect.Value) bool { +func AfterLogic(w http.ResponseWriter, r *http.Request, l reflect.Value) bool { m := l.MethodByName("AfterLogic") if m.IsValid() { - m.Call([]reflect.Value{reflect.ValueOf(w), reflect.ValueOf(r), reflect.ValueOf(resp)}) + m.Call([]reflect.Value{reflect.ValueOf(w), reflect.ValueOf(r)}) return true } return false