处理 有问题的handler

This commit is contained in:
eson
2023-07-21 14:20:21 +08:00
parent 44a3666d68
commit 373d5dca45
74 changed files with 174 additions and 3485 deletions

View File

@@ -4,6 +4,7 @@ import (
"fmt"
"fusenapi/utils/auth"
"fusenapi/utils/basic"
"log"
"net/http"
"context"
@@ -18,6 +19,8 @@ type RedirectLogic struct {
logx.Logger
ctx context.Context
svcCtx *svc.ServiceContext
RedirectUrl string
}
func NewRedirectLogic(ctx context.Context, svcCtx *svc.ServiceContext) *RedirectLogic {
@@ -33,35 +36,32 @@ func NewRedirectLogic(ctx context.Context, svcCtx *svc.ServiceContext) *Redirect
// }
// 处理逻辑后 w,r 如:重定向
func (l *RedirectLogic) AfterLogic(w http.ResponseWriter, r *http.Request, resp *basic.Response) {
html := `
func (l *RedirectLogic) AfterLogic(w http.ResponseWriter, r *http.Request) {
if l.RedirectUrl != "" {
html := fmt.Sprintf(`
<!DOCTYPE html>
<html>
<head>
<title>Redirect</title>
<script type="text/javascript">
window.onload = function() {
const params = new URLSearchParams(window.location.search);
const url = params.get('url');
if (url) {
window.location = url;
} else {
document.body.innerHTML = 'url parameter is required';
}
window.location = %s;
}
</script>
</head>
<body>
</body>
</html>
`
`, l.RedirectUrl)
fmt.Fprintln(w, html)
}
fmt.Fprintln(w, html)
}
func (l *RedirectLogic) Redirect(req *types.Request, userinfo *auth.UserInfo) (resp *basic.Response) {
func (l *RedirectLogic) Redirect(req *types.RequestRedirect, userinfo *auth.UserInfo) (resp *basic.Response) {
// 返回值必须调用Set重新返回, resp可以空指针调用 resp.SetStatus(basic.CodeOK, data)
// userinfo 传入值时, 一定不为null
l.RedirectUrl = req.Url
log.Println(req.Url)
return resp.SetStatus(basic.CodeOK)
}