From fc4352f8302cf87bfbab2a4e3161724ada878a7f Mon Sep 17 00:00:00 2001 From: "zcool321@sina.com" <1234qwer> Date: Sun, 5 Apr 2020 23:17:48 +0800 Subject: [PATCH] add set GoFrame server name --- ChangeLog.md | 5 ++++- example/main.go | 13 +++++++++---- gtoken/gtoken.go | 4 +++- 3 files changed, 16 insertions(+), 6 deletions(-) diff --git a/ChangeLog.md b/ChangeLog.md index 759f8a4..85541f6 100644 --- a/ChangeLog.md +++ b/ChangeLog.md @@ -1,6 +1,9 @@ Change Log 更新说明 ------------------------------ -## 2020-04-1 v1.3.16 +## 2020-04-05 v1.3.17 +1. 支持配置GoFrame serverName字段,默认不需要配置; + +## 2020-04-01 v1.3.16 1. 支持路径排除配置 ## 2020-03-31 v1.3.15 diff --git a/example/main.go b/example/main.go index 460ba44..a64ace6 100644 --- a/example/main.go +++ b/example/main.go @@ -8,8 +8,12 @@ import ( "github.com/gogf/gf/text/gstr" ) +var TestServerName string + +//var TestServerName string = "gtoken" + func main() { - g.Server().Run() + g.Server(TestServerName).Run() } // 管理初始化顺序. @@ -24,7 +28,7 @@ func initConfig() { v := g.View() c := g.Config() - s := g.Server() + s := g.Server(TestServerName) path := "" // 配置对象及视图对象配置 @@ -53,7 +57,7 @@ func initConfig() { */ func bindRouter() { - s := g.Server() + s := g.Server(TestServerName) s.BindMiddleware("/*", CORS) // 调试路由 @@ -73,6 +77,7 @@ func bindRouter() { loginFunc := Login // 启动gtoken gfToken := >oken.GfToken{ + ServerName: TestServerName, //Timeout: 10 * 1000, CacheMode: g.Config().GetInt8("gtoken.cache-mode"), LoginPath: "/login", @@ -92,7 +97,7 @@ func bindRouter() { */ func initRouter() { - s := g.Server() + s := g.Server(TestServerName) // 绑定路由 bindRouter() diff --git a/gtoken/gtoken.go b/gtoken/gtoken.go index 540fb8f..6064645 100644 --- a/gtoken/gtoken.go +++ b/gtoken/gtoken.go @@ -22,6 +22,8 @@ const ( // GfToken gtoken结构体 type GfToken struct { + // GoFrame server name + ServerName string // 缓存模式 1 gcache 2 gredis 默认1 CacheMode int8 // 缓存key @@ -168,7 +170,7 @@ func (m *GfToken) Start() bool { } glog.Info("[GToken][params:" + m.String() + "]start... ") - s := g.Server() + s := g.Server(m.ServerName) // 缓存模式 if m.CacheMode > CacheModeRedis {