修改tpl的参数传入问题

This commit is contained in:
eson 2023-07-21 11:24:26 +08:00
parent bfa1872595
commit 44a3666d68
9 changed files with 15 additions and 11 deletions

View File

@ -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)
}
}

View File

@ -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) {

View File

@ -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)
}
}

View File

@ -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) {

View File

@ -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)
}
}

View File

@ -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),
},
},

View File

@ -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) {

View File

@ -12,5 +12,5 @@ import "basic.api"
service assistant {
// 处理重定向
@handler RedirectHandler
get /api/redirect(request) returns (response);
get /api/assistant/redirect(request) returns (response);
}

View File

@ -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