From 7c8ab5bd920ddca16a11f7db5606fd1c8638b253 Mon Sep 17 00:00:00 2001 From: like Date: Tue, 31 May 2022 16:59:03 +0800 Subject: [PATCH] =?UTF-8?q?=E7=94=B3=E8=AF=B7=E4=BD=BF=E7=94=A8=E6=9C=9F?= =?UTF-8?q?=E9=99=90=E6=97=B6=E9=97=B4=E9=80=BB=E8=BE=91=E5=88=A4=E6=96=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .beagle.yml | 6 +++--- go.mod | 1 + go.sum | 7 ++++++- src/handler/proxyhandler.go | 14 +++++++++++--- 4 files changed, 21 insertions(+), 7 deletions(-) diff --git a/.beagle.yml b/.beagle.yml index 56ca583..c96f3a9 100644 --- a/.beagle.yml +++ b/.beagle.yml @@ -50,7 +50,7 @@ steps: base: registry.cn-qingdao.aliyuncs.com/wod/alpine-glibc:3.12 dockerfile: .beagle/dockerfile repo: gzgajzapi/apaas-meshproxy - Version: "v3.0.6" + Version: "v3.0.7" channel: alpha args: "TARGETOS=linux,TARGETARCH=amd64" registry: hub.wodcloud.com @@ -87,8 +87,8 @@ steps: REGISTRY_PASSWORD: from_secret: REGISTRY_PASSWORD settings: - source: hub.wodcloud.com/gzgajzapi/apaas-meshproxy:v3.0.6-alpha - target: hub.wodcloud.com/gzgajzapi/apaas-meshproxy:v3.0.6 + source: hub.wodcloud.com/gzgajzapi/apaas-meshproxy:v3.0.7-alpha + target: hub.wodcloud.com/gzgajzapi/apaas-meshproxy:v3.0.7 registry: hub.wodcloud.com --- diff --git a/go.mod b/go.mod index 9fbd64b..1ec0a9a 100644 --- a/go.mod +++ b/go.mod @@ -8,6 +8,7 @@ require ( github.com/gin-gonic/gin v1.6.3 github.com/go-redis/redis v6.15.9+incompatible github.com/go-sql-driver/mysql v1.6.0 + github.com/golang-module/carbon/v2 v2.1.8 github.com/lib/pq v1.10.0 github.com/natefinch/lumberjack v2.0.0+incompatible github.com/sirupsen/logrus v1.8.1 diff --git a/go.sum b/go.sum index 8913019..166e6f9 100644 --- a/go.sum +++ b/go.sum @@ -46,6 +46,8 @@ github.com/go-redis/redis v6.15.9+incompatible/go.mod h1:NAIEuMOZ/fxfXJIrKDQDz8w github.com/go-sql-driver/mysql v1.6.0 h1:BCTh4TKNUYmOmMUcQ3IipzF5prigylS7XXjEkfCHuOE= github.com/go-sql-driver/mysql v1.6.0/go.mod h1:DCzpHaOWr8IXmIStZouvnhqoel9Qv2LBy8hT2VhHyBg= github.com/go-task/slim-sprig v0.0.0-20210107165309-348f09dbbbc0/go.mod h1:fyg7847qk6SyHyPtNmDHnmrv/HOrqktSC+C9fM+CJOE= +github.com/golang-module/carbon/v2 v2.1.8 h1:pBBmSuLjeXZPzRwGqmZE97wyg6EnEqkFFEq6tlmGwHA= +github.com/golang-module/carbon/v2 v2.1.8/go.mod h1:NF5unWf838+pyRY0o+qZdIwBMkFf7w0hmLIguLiEpzU= github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= github.com/golang/protobuf v1.3.3/go.mod h1:vzj43D7+SQXF/4pzW/hwtAqwc6iTitCiVSaWz5lYuqw= github.com/golang/protobuf v1.4.0-rc.1/go.mod h1:ceaxUfeHdC40wWswd/P6IGgMaK3YpKi5j83Wpe3EHw8= @@ -122,8 +124,9 @@ github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+ github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4= -github.com/stretchr/testify v1.5.1 h1:nOGnQDM7FYENwehXlg/kFVnos3rEvtKTjRvOWSzb6H4= github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA= +github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY= +github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/syndtr/goleveldb v1.0.0 h1:fBdIW9lB4Iz0n9khmH8w27SJ3QEJ7+IgjPEwGSZiFdE= github.com/syndtr/goleveldb v1.0.0/go.mod h1:ZVVdQEZoIme9iO1Ch2Jdy24qqXrMMOU6lpPAyBWyWuQ= github.com/tealeg/xlsx v1.0.5 h1:+f8oFmvY8Gw1iUXzPk+kz+4GpbDZPK1FhPiQRd+ypgE= @@ -207,4 +210,6 @@ gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.3.0/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY= gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ= +gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo= +gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= launchpad.net/gocheck v0.0.0-20140225173054-000000000087/go.mod h1:hj7XX3B/0A+80Vse0e+BUHsHMTEhd0O4cpUHr/e/BUM= diff --git a/src/handler/proxyhandler.go b/src/handler/proxyhandler.go index c275ce5..7912223 100644 --- a/src/handler/proxyhandler.go +++ b/src/handler/proxyhandler.go @@ -7,6 +7,7 @@ import ( "encoding/json" "errors" "fmt" + "github.com/golang-module/carbon/v2" "io/ioutil" "log" "net/http" @@ -76,14 +77,17 @@ func Proxy(c *gin.Context) { c.JSON(200, res) return } - nowTime := time.Now().Format("2006-01-02") - if proxyData.RequestStartTime > nowTime { + + requestStartTime := FormatDateToCarbon(proxyData.RequestStartTime) + requestEndTime := FormatDateToCarbon(proxyData.RequestEndTime) + now := carbon.Now(carbon.Shanghai) + if requestStartTime.Gt(now) { res := model.WebRes{} res.ErrMsg = `申请使用期限未开始` c.JSON(200, res) return } - if proxyData.RequestEndTime < nowTime { + if requestEndTime.Lt(now) { res := model.WebRes{} res.ErrMsg = `申请使用期限已过期` c.JSON(200, res) @@ -256,6 +260,10 @@ func Proxy(c *gin.Context) { } +func FormatDateToCarbon(date string) carbon.Carbon { + return carbon.Parse(strings.Replace(strings.TrimRight(strings.TrimSpace(date), "Z"), "T", " ", -1), carbon.Shanghai) +} + func CheckStaticFile(path string) bool { if strings.HasSuffix(path, ".css") || strings.HasSuffix(path, ".js") || strings.HasSuffix(path, ".woff2") || strings.HasSuffix(path, ".jpg") || strings.HasSuffix(path, ".svg") || strings.HasSuffix(path, ".woff") || strings.HasSuffix(path, ".html") || strings.HasSuffix(path, ".ttf") { -- 2.26.0