From 415863ab61820e2ceb367e1af352ee057af0bd0e Mon Sep 17 00:00:00 2001 From: ning <710leo@gmail.com> Date: Mon, 31 Jul 2023 14:43:19 +0800 Subject: [PATCH] check datasource --- center/router/router.go | 4 ++++ center/router/router_datasource.go | 25 +++++++++++++++++++++++++ 2 files changed, 29 insertions(+) diff --git a/center/router/router.go b/center/router/router.go index c0d220a3..eace233a 100644 --- a/center/router/router.go +++ b/center/router/router.go @@ -42,6 +42,8 @@ type Router struct { UserCache *memsto.UserCacheType UserGroupCache *memsto.UserGroupCacheType Ctx *ctx.Context + + DatasourceCheckHook func(*gin.Context) bool } func New(httpConfig httpx.Config, center cconf.Center, operations cconf.Operation, ds *memsto.DatasourceCacheType, ncc *memsto.NotifyConfigCacheType, @@ -62,6 +64,8 @@ func New(httpConfig httpx.Config, center cconf.Center, operations cconf.Operatio UserCache: uc, UserGroupCache: ugc, Ctx: ctx, + + DatasourceCheckHook: func(ctx *gin.Context) bool { return false }, } } diff --git a/center/router/router_datasource.go b/center/router/router_datasource.go index 282c4257..9db48dcc 100644 --- a/center/router/router_datasource.go +++ b/center/router/router_datasource.go @@ -25,6 +25,11 @@ type listReq struct { } func (rt *Router) datasourceList(c *gin.Context) { + if rt.DatasourceCheckHook(c) { + Render(c, []int{}, nil) + return + } + var req listReq ginx.BindJSON(c, &req) @@ -65,6 +70,11 @@ func (rt *Router) datasourceBriefs(c *gin.Context) { } func (rt *Router) datasourceUpsert(c *gin.Context) { + if rt.DatasourceCheckHook(c) { + Render(c, []int{}, nil) + return + } + var req models.Datasource ginx.BindJSON(c, &req) username := Username(c) @@ -165,6 +175,11 @@ func DatasourceCheck(ds models.Datasource) error { } func (rt *Router) datasourceGet(c *gin.Context) { + if rt.DatasourceCheckHook(c) { + Render(c, []int{}, nil) + return + } + var req models.Datasource ginx.BindJSON(c, &req) err := req.Get(rt.Ctx) @@ -172,6 +187,11 @@ func (rt *Router) datasourceGet(c *gin.Context) { } func (rt *Router) datasourceUpdataStatus(c *gin.Context) { + if rt.DatasourceCheckHook(c) { + Render(c, []int{}, nil) + return + } + var req models.Datasource ginx.BindJSON(c, &req) username := Username(c) @@ -181,6 +201,11 @@ func (rt *Router) datasourceUpdataStatus(c *gin.Context) { } func (rt *Router) datasourceDel(c *gin.Context) { + if rt.DatasourceCheckHook(c) { + Render(c, []int{}, nil) + return + } + var ids []int64 ginx.BindJSON(c, &ids) err := models.DatasourceDel(rt.Ctx, ids) -- GitLab