|
@@ -33,12 +33,17 @@ func main() { |
|
@@ -33,12 +33,17 @@ func main() { |
33
|
|
33
|
|
34
|
// 服务初始化
|
34
|
// 服务初始化
|
35
|
opts := make([]rest.RunOption, 0)
|
35
|
opts := make([]rest.RunOption, 0)
|
36
|
- opt := rest.WithCustomCors(func(header http.Header) {
|
36
|
+ opts = append(opts, rest.WithCustomCors(func(header http.Header) {
|
37
|
header.Set("Access-Control-Allow-Headers", "*")
|
37
|
header.Set("Access-Control-Allow-Headers", "*")
|
38
|
}, func(writer http.ResponseWriter) {
|
38
|
}, func(writer http.ResponseWriter) {
|
39
|
|
39
|
|
40
|
- })
|
|
|
41
|
- opts = append(opts, opt)
|
40
|
+ }))
|
|
|
41
|
+ opts = append(opts, rest.WithUnauthorizedCallback(func(w http.ResponseWriter, r *http.Request, err error) {
|
|
|
42
|
+ if err != nil {
|
|
|
43
|
+ logx.Debugf("unauthorized: %s \n", err.Error())
|
|
|
44
|
+ }
|
|
|
45
|
+ }))
|
|
|
46
|
+
|
42
|
server := rest.MustNewServer(c.RestConf, opts...)
|
47
|
server := rest.MustNewServer(c.RestConf, opts...)
|
43
|
defer server.Stop()
|
48
|
defer server.Stop()
|
44
|
ctx := svc.NewServiceContext(c)
|
49
|
ctx := svc.NewServiceContext(c)
|
|
@@ -73,6 +78,7 @@ func systemSetup(c config.Config) { |
|
@@ -73,6 +78,7 @@ func systemSetup(c config.Config) { |
73
|
httpx.SetErrorHandlerCtx(func(ctx context.Context, err error) (int, any) {
|
78
|
httpx.SetErrorHandlerCtx(func(ctx context.Context, err error) (int, any) {
|
74
|
return http.StatusOK, result.Error(xerr.ServerCommonError, err.Error())
|
79
|
return http.StatusOK, result.Error(xerr.ServerCommonError, err.Error())
|
75
|
})
|
80
|
})
|
|
|
81
|
+
|
76
|
// 系统成功应答包装
|
82
|
// 系统成功应答包装
|
77
|
httpx.SetOkHandler(func(ctx context.Context, a any) any {
|
83
|
httpx.SetOkHandler(func(ctx context.Context, a any) any {
|
78
|
return result.Success(a)
|
84
|
return result.Success(a)
|