From eddfe263084294468399c6ebb4fb92bed0ab4489 Mon Sep 17 00:00:00 2001 From: linwenxiang <991154416@qq.com> Date: Wed, 7 Apr 2021 23:01:32 +0800 Subject: [PATCH] =?UTF-8?q?feat=20=E2=9C=A8=20=E9=AA=8C=E8=AF=81=E7=A0=81s?= =?UTF-8?q?tore=E6=94=AF=E6=8C=81go-admin=20cache?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Dockerfile | 2 +- cmd/api/server.go | 6 +++++- common/middleware/handler/auth.go | 5 +++++ go.mod | 2 +- scripts/k8s/deploy.yml | 3 --- 5 files changed, 12 insertions(+), 6 deletions(-) diff --git a/Dockerfile b/Dockerfile index 8f4facd2..71c81a82 100644 --- a/Dockerfile +++ b/Dockerfile @@ -23,4 +23,4 @@ COPY --from=builder /usr/share/zoneinfo/Asia/Shanghai /etc/localtime EXPOSE 8000 -CMD ["/go-admin","server","-c", "/config/settings.yml"] +CMD ["/go-admin","server","-c", "/config/settings.yml"] \ No newline at end of file diff --git a/cmd/api/server.go b/cmd/api/server.go index dde90443..7e382cb8 100644 --- a/cmd/api/server.go +++ b/cmd/api/server.go @@ -3,6 +3,8 @@ package api import ( "context" "fmt" + "github.com/go-admin-team/go-admin-core/tools/captcha" + "go-admin/common/middleware/handler" "log" "net/http" "os" @@ -71,6 +73,8 @@ func setup() { log.Fatalf("cache setup error, %s\n", err.Error()) } sdk.Runtime.SetCacheAdapter(cacheAdapter) + //5. 设置验证码store + handler.SetStore(captcha.NewCacheStore(cacheAdapter, 600)) usageStr := `starting api server...` log.Println(usageStr) @@ -150,4 +154,4 @@ func run() error { func tip() { usageStr := `欢迎使用 ` + pkg.Green(`go-admin `+global.Version) + ` 可以使用 ` + pkg.Red(`-h`) + ` 查看命令` fmt.Printf("%s \n\n", usageStr) -} \ No newline at end of file +} diff --git a/common/middleware/handler/auth.go b/common/middleware/handler/auth.go index 1021c59a..392d227d 100644 --- a/common/middleware/handler/auth.go +++ b/common/middleware/handler/auth.go @@ -20,6 +20,11 @@ import ( var store = base64Captcha.DefaultMemStore +// SetStore 设置store +func SetStore(s base64Captcha.Store) { + store = s +} + func PayloadFunc(data interface{}) jwt.MapClaims { if v, ok := data.(map[string]interface{}); ok { u, _ := v["user"].(SysUser) diff --git a/go.mod b/go.mod index 08141506..a766e1e5 100644 --- a/go.mod +++ b/go.mod @@ -8,7 +8,7 @@ require ( github.com/aliyun/aliyun-oss-go-sdk v0.0.0-20190307165228-86c17b95fcd5 github.com/casbin/casbin/v2 v2.25.1 github.com/gin-gonic/gin v1.6.3 - github.com/go-admin-team/go-admin-core v1.3.4-0.20210331124757-4c4d0bf6c336 + github.com/go-admin-team/go-admin-core v1.3.0-rc.0.0.20210407093008-7e27bec63f3e github.com/google/uuid v1.2.0 github.com/mojocn/base64Captcha v1.3.1 github.com/mssola/user_agent v0.5.2 diff --git a/scripts/k8s/deploy.yml b/scripts/k8s/deploy.yml index 4a8d16b3..9931afaf 100644 --- a/scripts/k8s/deploy.yml +++ b/scripts/k8s/deploy.yml @@ -3,7 +3,6 @@ apiVersion: v1 kind: Service metadata: name: go-admin - namespace: go-admin labels: app: go-admin service: go-admin @@ -19,7 +18,6 @@ apiVersion: apps/v1 kind: Deployment metadata: name: go-admin-v1 - namespace: go-admin labels: app: go-admin version: v1 @@ -35,7 +33,6 @@ spec: app: go-admin version: v1 spec: - serviceAccountName: go-admin-go-admin containers: - name: go-admin image: ${IMAGE}