...
|
...
|
@@ -33,12 +33,17 @@ func main() { |
|
|
|
|
|
// 服务初始化
|
|
|
opts := make([]rest.RunOption, 0)
|
|
|
opt := rest.WithCustomCors(func(header http.Header) {
|
|
|
opts = append(opts, rest.WithCustomCors(func(header http.Header) {
|
|
|
header.Set("Access-Control-Allow-Headers", "*")
|
|
|
}, func(writer http.ResponseWriter) {
|
|
|
|
|
|
})
|
|
|
opts = append(opts, opt)
|
|
|
}))
|
|
|
opts = append(opts, rest.WithUnauthorizedCallback(func(w http.ResponseWriter, r *http.Request, err error) {
|
|
|
if err != nil {
|
|
|
logx.Debugf("unauthorized: %s \n", err.Error())
|
|
|
}
|
|
|
}))
|
|
|
|
|
|
server := rest.MustNewServer(c.RestConf, opts...)
|
|
|
defer server.Stop()
|
|
|
ctx := svc.NewServiceContext(c)
|
...
|
...
|
@@ -73,6 +78,7 @@ func systemSetup(c config.Config) { |
|
|
httpx.SetErrorHandlerCtx(func(ctx context.Context, err error) (int, any) {
|
|
|
return http.StatusOK, result.Error(xerr.ServerCommonError, err.Error())
|
|
|
})
|
|
|
|
|
|
// 系统成功应答包装
|
|
|
httpx.SetOkHandler(func(ctx context.Context, a any) any {
|
|
|
return result.Success(a)
|
...
|
...
|
|