From 9a28b2785da81edfa9463c272ca38ae957aadfd2 Mon Sep 17 00:00:00 2001 From: flyfox Date: Tue, 25 Jan 2022 00:21:31 +0800 Subject: [PATCH] add file cache --- ChangeLog.md | 2 +- gtoken/gtoken.go | 4 ++-- gtoken/gtoken_conts.go | 6 ++++-- gtoken/gtoken_msg_test.go | 14 ++++++++++++++ gtoken/gtoken_test.go | 1 - 5 files changed, 21 insertions(+), 6 deletions(-) create mode 100644 gtoken/gtoken_msg_test.go diff --git a/ChangeLog.md b/ChangeLog.md index 24a729c..1b850e1 100644 --- a/ChangeLog.md +++ b/ChangeLog.md @@ -1,6 +1,6 @@ Change Log 更新说明 ------------------------------ -## 2022-01-24 v1.5.1 +## 2022-01-24 v1.5.2 1. 支持缓存使用文件存储; ## 2022-01-12 v1.5.0 diff --git a/gtoken/gtoken.go b/gtoken/gtoken.go index 76977a5..933ae4f 100644 --- a/gtoken/gtoken.go +++ b/gtoken/gtoken.go @@ -150,8 +150,8 @@ func (m *GfToken) AuthPath(ctx context.Context, urlPath string) bool { } // 分组拦截,登录接口不拦截 if m.MiddlewareType == MiddlewareTypeGroup { - if gstr.HasSuffix(urlPath, m.LoginPath) || - gstr.HasSuffix(urlPath, m.LogoutPath) { + if (m.LoginPath != "" && gstr.HasSuffix(urlPath, m.LoginPath)) || + (m.LogoutPath != "" && gstr.HasSuffix(urlPath, m.LogoutPath)) { return false } } diff --git a/gtoken/gtoken_conts.go b/gtoken/gtoken_conts.go index 471842f..f81a886 100644 --- a/gtoken/gtoken_conts.go +++ b/gtoken/gtoken_conts.go @@ -1,6 +1,8 @@ package gtoken -import "fmt" +import ( + "fmt" +) const ( CacheModeCache = 1 @@ -47,5 +49,5 @@ func msgLog(msg string, params ...interface{}) string { if len(params) == 0 { return DefaultLogPrefix + msg } - return DefaultLogPrefix + fmt.Sprintf(msg, params) + return DefaultLogPrefix + fmt.Sprintf(msg, params...) } diff --git a/gtoken/gtoken_msg_test.go b/gtoken/gtoken_msg_test.go new file mode 100644 index 0000000..3d9278b --- /dev/null +++ b/gtoken/gtoken_msg_test.go @@ -0,0 +1,14 @@ +package gtoken + +import ( + "testing" +) + +func TestMsg(t *testing.T) { + if msgLog("123") != "[GToken]123" { + t.Error("msg err") + } + if msgLog("123-%s-%d", "123", 44) != "[GToken]123-123-44" { + t.Error("msg sprintf err") + } +} diff --git a/gtoken/gtoken_test.go b/gtoken/gtoken_test.go index a854389..441665a 100644 --- a/gtoken/gtoken_test.go +++ b/gtoken/gtoken_test.go @@ -224,5 +224,4 @@ func BenchmarkEncryptDecryptToken(b *testing.B) { b.Error("error:", "token decrypt uuid error") } } - }