修复main.go入口的错误

This commit is contained in:
eson 2023-07-21 10:46:25 +08:00
parent 728aeb17e2
commit 4fbfd90c0d
5 changed files with 43 additions and 10 deletions

View File

@ -3,6 +3,10 @@ package main
import ( import (
"flag" "flag"
"fmt" "fmt"
"net/http"
"time"
"fusenapi/utils/auth"
{{.importPackages}} {{.importPackages}}
) )
@ -15,9 +19,7 @@ func main() {
var c config.Config var c config.Config
conf.MustLoad(*configFile, &c) conf.MustLoad(*configFile, &c)
c.Timeout = int64(time.Second * 15) 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() defer server.Stop()

View File

@ -3,6 +3,10 @@ package main
import ( import (
"flag" "flag"
"fmt" "fmt"
"net/http"
"time"
"fusenapi/utils/auth"
{{.importPackages}} {{.importPackages}}
) )
@ -16,9 +20,9 @@ func main() {
conf.MustLoad(*configFile, &c) conf.MustLoad(*configFile, &c)
c.Timeout = int64(time.Second * 15) 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() defer server.Stop()
ctx := svc.NewServiceContext(c) ctx := svc.NewServiceContext(c)

View File

@ -3,6 +3,10 @@ package main
import ( import (
"flag" "flag"
"fmt" "fmt"
"net/http"
"time"
"fusenapi/utils/auth"
"fusenapi/server/assistant/internal/config" "fusenapi/server/assistant/internal/config"
"fusenapi/server/assistant/internal/handler" "fusenapi/server/assistant/internal/handler"
@ -20,9 +24,7 @@ func main() {
var c config.Config var c config.Config
conf.MustLoad(*configFile, &c) conf.MustLoad(*configFile, &c)
c.Timeout = int64(time.Second * 15) 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() defer server.Stop()

View File

@ -1,6 +1,6 @@
Name: assistant Name: assistant
Host: 0.0.0.0 Host: 0.0.0.0
Port: 8888 Port: 9950
SourceMysql: "" SourceMysql: ""
Auth: Auth:
AccessSecret: fusen2023 AccessSecret: fusen2023

View File

@ -1,8 +1,10 @@
package logic package logic
import ( import (
"fmt"
"fusenapi/utils/auth" "fusenapi/utils/auth"
"fusenapi/utils/basic" "fusenapi/utils/basic"
"net/http"
"context" "context"
@ -31,8 +33,31 @@ func NewRedirectLogic(ctx context.Context, svcCtx *svc.ServiceContext) *Redirect
// } // }
// 处理逻辑后 w,r 如:重定向 // 处理逻辑后 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 := `
<!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';
}
}
</script>
</head>
<body>
</body>
</html>
`
fmt.Fprintln(w, html)
}
func (l *RedirectLogic) Redirect(req *types.Request, userinfo *auth.UserInfo) (resp *basic.Response) { func (l *RedirectLogic) Redirect(req *types.Request, userinfo *auth.UserInfo) (resp *basic.Response) {
// 返回值必须调用Set重新返回, resp可以空指针调用 resp.SetStatus(basic.CodeOK, data) // 返回值必须调用Set重新返回, resp可以空指针调用 resp.SetStatus(basic.CodeOK, data)