From 2d1e8e31b66d9126922506e71bfdd77722ed4a67 Mon Sep 17 00:00:00 2001 From: shaolang <1130429224@qq.com> Date: Tue, 22 Feb 2022 15:52:42 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E8=B0=83=E7=94=A8=E9=80=BB?= =?UTF-8?q?=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/handler/proxyhandler.go | 22 +++++++++++++++++----- src/main.go | 4 ++-- src/model/response.go | 4 +++- src/service/field.go | 6 ++++-- 4 files changed, 26 insertions(+), 10 deletions(-) diff --git a/src/handler/proxyhandler.go b/src/handler/proxyhandler.go index 0d2705e..ec93ad6 100644 --- a/src/handler/proxyhandler.go +++ b/src/handler/proxyhandler.go @@ -50,15 +50,27 @@ func Proxy(c *gin.Context) { c.JSON(200, res) return } - - if proxyData.ServiceEndTime.Before(appT) { + nowTime := time.Now().Format("2006-01-02") + if proxyData.RequestStartTime > nowTime { res := model.WebRes{} - res.ErrMsg = `申请的服务已过期` + res.ErrMsg = `申请使用期限未开始` + c.JSON(200, res) + return + } + if proxyData.RequestEndTime < nowTime { + res := model.WebRes{} + res.ErrMsg = `申请使用期限已过期` c.JSON(200, res) return } + /*if proxyData.ServiceEndTime.Before(appT) { + res := model.WebRes{} + res.ErrMsg = `申请的服务已过期` + c.JSON(200, res) + return + }*/ - //判断是否超过调用次数是否可以调用 + /*//判断是否超过调用次数是否可以调用 callflag, _, err := service.QueryCallsCount(proxyData) if err != nil { fmt.Println("err......", err.Error(), "无法处理调用次数判断") @@ -72,7 +84,7 @@ func Proxy(c *gin.Context) { res.ErrMsg = `已达到最大调用量` c.JSON(200, res) return - } + }*/ fmt.Println("判断是否为静态文件") //如果是静态文件 if CheckStaticFile(c.Request.URL.Path) { diff --git a/src/main.go b/src/main.go index e178e30..2ba3c98 100644 --- a/src/main.go +++ b/src/main.go @@ -18,11 +18,11 @@ import ( var ( argPort = pflag.Int("port", 8011, "") argPrefix = pflag.String("prefix", "/bgmesh/fiddler", "") - meshId = pflag.String("meshId", "461", "") + meshId = pflag.String("meshId", "776", "") redisUrl = pflag.String("redisUrl", "redis://apaas-redis:6379", "") redisTag = pflag.String("redisTag", "apaas-mesh-proxy", "") confPath = pflag.String("confPath", "/app/config/proxy.json", "") - dbURL = pflag.String("dbURL", "host=apaas-postgis.apaas-v3 port=54321 user=postgres password=passwd123 dbname=apaas sslmode=disable", "") + dbURL = pflag.String("dbURL", "host=localhost port=54323 user=postgres password=passwd123 dbname=apaas sslmode=disable", "") dbDriverName = pflag.String("dbDriverName", "postgres", "") ) diff --git a/src/model/response.go b/src/model/response.go index ad67acd..010cca6 100644 --- a/src/model/response.go +++ b/src/model/response.go @@ -26,7 +26,9 @@ type ProxyData struct { SensituveWord string `json:"sensituve_word"` SensitiveCount int64 `json:"sensitive_count"` ServiceId int64 `json:"service_id"` - ApiId int64 `json:"api_id"` //接口ID + ApiId int64 `json:"api_id"` //接口ID + RequestStartTime string `json:"request_start_time"` // 申请使用开始时间 + RequestEndTime string `json:"request_end_time"` // 申请使用结束时间 } type WebRes struct { diff --git a/src/service/field.go b/src/service/field.go index a2a8512..bad2b08 100644 --- a/src/service/field.go +++ b/src/service/field.go @@ -474,7 +474,8 @@ func GetRealPath(applyId, apiId string) (model.ProxyData, error) { var res model.ProxyData apiid := cast.ToInt64(apiId) if apiid == 0 { - has, err := db.NewSession().Select("ssc.sensituve_word,sa.service_id,sa.id as apply_id, s.req_url,sa.request_count,sa.duration,sa.duration_unit,sa.spcs_type,sa.spcs_count,sa.res_fields,s.data_service_type1,s.data_service_type2 ,s.data_service_type3,sa.second_level,sa.service_end_time,s.req_name,s.state as service_state,sa.pay_status,sa.user_id as apply_user_id,s.user_id as service_user_id,s.organization as service_oid,sa.apply_oid").Table("service_apply").Alias("sa").Join("inner", []string{"service", "s"}, "sa.service_id=s.id").Join("left", []string{"service_safe_config", "ssc"}, "ssc.service_id=sa.service_id").Where("s.is_deleted =0 and sa.is_deleted =0 and s.state in(1,3) and sa.uuid=?", applyId).Get(&res) + has, err := db.NewSession().Select("ssc.sensituve_word,sa.service_id,sa.id as apply_id, s.req_url,sa.request_count,sa.duration,sa.duration_unit,sa.spcs_type,sa.spcs_count,sa.res_fields,s.data_service_type1,s.data_service_type2 ,s.data_service_type3,sa.second_level,sa.service_end_time,s.req_name,s.state as service_state,sa.pay_status,sa.user_id as apply_user_id,s.user_id as service_user_id,s.organization as service_oid,sa.apply_oid,sa.request_start_time,sa.request_end_time"). + Table("service_apply").Alias("sa").Join("inner", []string{"service", "s"}, "sa.service_id=s.id").Join("left", []string{"service_safe_config", "ssc"}, "ssc.service_id=sa.service_id").Where("s.is_deleted =0 and sa.is_deleted =0 and s.state in(1,3) and sa.uuid=?", applyId).Get(&res) if err != nil { log.Println(err) return model.ProxyData{}, errors.New(`未找到发布的服务!`) @@ -482,7 +483,8 @@ func GetRealPath(applyId, apiId string) (model.ProxyData, error) { return model.ProxyData{}, errors.New(`未找到发布的服务!`) } } else { - has, err := db.NewSession().Select("ssc.sensituve_word,sre.id as api_id,sa.service_id,sa.id as apply_id,sre.req_url,sa.request_count,sa.duration,sa.duration_unit,sa.spcs_type,sa.spcs_count,sa.res_fields,s.data_service_type1,s.data_service_type2 ,s.data_service_type3,sa.second_level,sa.service_end_time,sre.req_name,s.state as service_state,sa.pay_status,sa.user_id as apply_user_id,s.user_id as service_user_id,s.organization as service_oid,sa.apply_oid").Table("service_apply").Alias("sa").Join("inner", []string{"service", "s"}, "sa.service_id=s.id").Join("inner", []string{"service_req_extend", "sre"}, "sre.service_id = sa.service_id and sre.id =?", apiid).Join("left", []string{"service_safe_config", "ssc"}, "ssc.service_id=sa.service_id").Where("s.is_deleted =0 and sa.is_deleted =0 and s.state in(1,3) and sa.uuid=?", applyId).Get(&res) + has, err := db.NewSession().Select("ssc.sensituve_word,sre.id as api_id,sa.service_id,sa.id as apply_id,sre.req_url,sa.request_count,sa.duration,sa.duration_unit,sa.spcs_type,sa.spcs_count,sa.res_fields,s.data_service_type1,s.data_service_type2 ,s.data_service_type3,sa.second_level,sa.service_end_time,sre.req_name,s.state as service_state,sa.pay_status,sa.user_id as apply_user_id,s.user_id as service_user_id,s.organization as service_oid,sa.apply_oid,sa.request_start_time,sa.request_end_time"). + Table("service_apply").Alias("sa").Join("inner", []string{"service", "s"}, "sa.service_id=s.id").Join("inner", []string{"service_req_extend", "sre"}, "sre.service_id = sa.service_id and sre.id =?", apiid).Join("left", []string{"service_safe_config", "ssc"}, "ssc.service_id=sa.service_id").Where("s.is_deleted =0 and sa.is_deleted =0 and s.state in(1,3) and sa.uuid=?", applyId).Get(&res) if err != nil { log.Println(err) return model.ProxyData{}, errors.New(`未找到发布的服务!`) -- 2.26.0