修改tpl的参数传入问题
This commit is contained in:
		
							parent
							
								
									bfa1872595
								
							
						
					
					
						commit
						44a3666d68
					
				| @ -26,7 +26,7 @@ func {{.HandlerName}}(svcCtx *svc.ServiceContext) http.HandlerFunc { | |||||||
| 
 | 
 | ||||||
| 		{{if .HasResp}}resp{{end}} := l.{{.Call}}({{if .HasRequest}}&req, {{end}}userinfo) | 		{{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) | 			basic.NormalAfterLogic(w, r, resp) | ||||||
| 		} | 		} | ||||||
| 	} | 	} | ||||||
|  | |||||||
| @ -26,7 +26,7 @@ func New{{.logic}}(ctx context.Context, svcCtx *svc.ServiceContext) *{{.logic}} | |||||||
| // } | // } | ||||||
| 
 | 
 | ||||||
| // 处理逻辑后 w,r 如:重定向 | // 处理逻辑后 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) { | func (l *{{.logic}}) {{.function}}({{.request}}, userinfo *auth.UserInfo) (resp *basic.Response) { | ||||||
|  | |||||||
| @ -25,7 +25,7 @@ func {{.HandlerName}}(svcCtx *svc.ServiceContext) http.HandlerFunc { | |||||||
| 
 | 
 | ||||||
| 		{{if .HasResp}}resp{{end}} := l.{{.Call}}({{if .HasRequest}}&req, {{end}}userinfo) | 		{{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) | 			basic.NormalAfterLogic(w, r, resp) | ||||||
| 		} | 		} | ||||||
| 	} | 	} | ||||||
|  | |||||||
| @ -26,7 +26,7 @@ func New{{.logic}}(ctx context.Context, svcCtx *svc.ServiceContext) *{{.logic}} | |||||||
| // } | // } | ||||||
| 
 | 
 | ||||||
| // 处理逻辑后 w,r 如:重定向 | // 处理逻辑后 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) { | func (l *{{.logic}}) {{.function}}({{.request}}, userinfo *auth.UserInfo) (resp *basic.Response) { | ||||||
|  | |||||||
| @ -28,7 +28,7 @@ func RedirectHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { | |||||||
| 
 | 
 | ||||||
| 		resp := l.Redirect(&req, userinfo) | 		resp := l.Redirect(&req, userinfo) | ||||||
| 
 | 
 | ||||||
| 		if !basic.AfterLogic(w, r, resp, rl) { | 		if !basic.AfterLogic(w, r, rl) { | ||||||
| 			basic.NormalAfterLogic(w, r, resp) | 			basic.NormalAfterLogic(w, r, resp) | ||||||
| 		} | 		} | ||||||
| 	} | 	} | ||||||
|  | |||||||
| @ -14,7 +14,7 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) { | |||||||
| 		[]rest.Route{ | 		[]rest.Route{ | ||||||
| 			{ | 			{ | ||||||
| 				Method:  http.MethodGet, | 				Method:  http.MethodGet, | ||||||
| 				Path:    "/api/redirect", | 				Path:    "/api/assistant/redirect", | ||||||
| 				Handler: RedirectHandler(serverCtx), | 				Handler: RedirectHandler(serverCtx), | ||||||
| 			}, | 			}, | ||||||
| 		}, | 		}, | ||||||
|  | |||||||
| @ -25,6 +25,8 @@ type UserGoogleLoginLogic struct { | |||||||
| 	logx.Logger | 	logx.Logger | ||||||
| 	ctx    context.Context | 	ctx    context.Context | ||||||
| 	svcCtx *svc.ServiceContext | 	svcCtx *svc.ServiceContext | ||||||
|  | 
 | ||||||
|  | 	redirectUrl string | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| func NewUserGoogleLoginLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UserGoogleLoginLogic { | 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) | 	log.Println(r, w) | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| func (l *UserGoogleLoginLogic) AfterLogic(w http.ResponseWriter, r *http.Request, resp *basic.Response) { | func (l *UserGoogleLoginLogic) AfterLogic(w http.ResponseWriter, r *http.Request) { | ||||||
| 	http.Redirect(w, r, "http://localhost:9900/redirect?uri=%s", http.StatusFound) | 	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) { | func (l *UserGoogleLoginLogic) UserGoogleLogin(req *types.RequestGoogleLogin, userinfo *auth.UserInfo) (resp *basic.Response) { | ||||||
|  | |||||||
| @ -12,5 +12,5 @@ import "basic.api" | |||||||
| service assistant { | service assistant { | ||||||
| 	// 处理重定向 | 	// 处理重定向 | ||||||
| 	@handler RedirectHandler | 	@handler RedirectHandler | ||||||
| 	get /api/redirect(request) returns (response); | 	get /api/assistant/redirect(request) returns (response); | ||||||
| } | } | ||||||
| @ -27,11 +27,11 @@ func BeforeLogic(w http.ResponseWriter, r *http.Request, l reflect.Value) (isNex | |||||||
| 	return true | 	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") | 	m := l.MethodByName("AfterLogic") | ||||||
| 	if m.IsValid() { | 	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 true | ||||||
| 	} | 	} | ||||||
| 	return false | 	return false | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user