From 4fbfd90c0da23c124ac63ebf0bf0b7f675649868 Mon Sep 17 00:00:00 2001 From: eson <9673575+githubcontent@user.noreply.gitee.com> Date: Fri, 21 Jul 2023 10:46:25 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8Dmain.go=E5=85=A5=E5=8F=A3?= =?UTF-8?q?=E7=9A=84=E9=94=99=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- goctl_template/api/main.tpl | 8 +++-- goctl_template_backend/api/main.tpl | 8 +++-- server/assistant/assistant.go | 6 ++-- server/assistant/etc/assistant.yaml | 2 +- .../assistant/internal/logic/redirectlogic.go | 29 +++++++++++++++++-- 5 files changed, 43 insertions(+), 10 deletions(-) diff --git a/goctl_template/api/main.tpl b/goctl_template/api/main.tpl index 6d173f86..f4a688cb 100644 --- a/goctl_template/api/main.tpl +++ b/goctl_template/api/main.tpl @@ -3,6 +3,10 @@ package main import ( "flag" "fmt" + "net/http" + "time" + + "fusenapi/utils/auth" {{.importPackages}} ) @@ -15,9 +19,7 @@ func main() { var c config.Config conf.MustLoad(*configFile, &c) c.Timeout = int64(time.Second * 15) - - server := rest.MustNewServer(c.RestConf, rest.WithCustomCors(auth.FsCors, func(w http.ResponseWriter) { - + server := rest.MustNewServer(c.RestConf, rest.WithCustomCors(auth.FsCors, func(w http.ResponseWriter) { })) defer server.Stop() diff --git a/goctl_template_backend/api/main.tpl b/goctl_template_backend/api/main.tpl index 1b353bcb..71e4fb99 100644 --- a/goctl_template_backend/api/main.tpl +++ b/goctl_template_backend/api/main.tpl @@ -3,6 +3,10 @@ package main import ( "flag" "fmt" + "net/http" + "time" + + "fusenapi/utils/auth" {{.importPackages}} ) @@ -16,9 +20,9 @@ func main() { conf.MustLoad(*configFile, &c) c.Timeout = int64(time.Second * 15) - server := rest.MustNewServer(c.RestConf, rest.WithCustomCors(auth.FsCors, func(w http.ResponseWriter) { - + server := rest.MustNewServer(c.RestConf, rest.WithCustomCors(auth.FsCors, func(w http.ResponseWriter) { })) + defer server.Stop() ctx := svc.NewServiceContext(c) diff --git a/server/assistant/assistant.go b/server/assistant/assistant.go index 2f0bf734..8ae0cf8e 100644 --- a/server/assistant/assistant.go +++ b/server/assistant/assistant.go @@ -3,6 +3,10 @@ package main import ( "flag" "fmt" + "net/http" + "time" + + "fusenapi/utils/auth" "fusenapi/server/assistant/internal/config" "fusenapi/server/assistant/internal/handler" @@ -20,9 +24,7 @@ func main() { var c config.Config conf.MustLoad(*configFile, &c) c.Timeout = int64(time.Second * 15) - server := rest.MustNewServer(c.RestConf, rest.WithCustomCors(auth.FsCors, func(w http.ResponseWriter) { - })) defer server.Stop() diff --git a/server/assistant/etc/assistant.yaml b/server/assistant/etc/assistant.yaml index 2c83cce3..4fd902f0 100644 --- a/server/assistant/etc/assistant.yaml +++ b/server/assistant/etc/assistant.yaml @@ -1,6 +1,6 @@ Name: assistant Host: 0.0.0.0 -Port: 8888 +Port: 9950 SourceMysql: "" Auth: AccessSecret: fusen2023 diff --git a/server/assistant/internal/logic/redirectlogic.go b/server/assistant/internal/logic/redirectlogic.go index d61d2a3a..a054a32d 100644 --- a/server/assistant/internal/logic/redirectlogic.go +++ b/server/assistant/internal/logic/redirectlogic.go @@ -1,8 +1,10 @@ package logic import ( + "fmt" "fusenapi/utils/auth" "fusenapi/utils/basic" + "net/http" "context" @@ -31,8 +33,31 @@ func NewRedirectLogic(ctx context.Context, svcCtx *svc.ServiceContext) *Redirect // } // 处理逻辑后 w,r 如:重定向 -// func (l *RedirectLogic) AfterLogic(w http.ResponseWriter, r *http.Request, resp *basic.Response) { -// } +func (l *RedirectLogic) AfterLogic(w http.ResponseWriter, r *http.Request, resp *basic.Response) { + html := ` + + + + Redirect + + + + + + ` + + fmt.Fprintln(w, html) +} func (l *RedirectLogic) Redirect(req *types.Request, userinfo *auth.UserInfo) (resp *basic.Response) { // 返回值必须调用Set重新返回, resp可以空指针调用 resp.SetStatus(basic.CodeOK, data)