From 4e08a78c267ee298a8b1f1c5bad93143257e3a81 Mon Sep 17 00:00:00 2001 From: yxh Date: Tue, 7 Jan 2020 22:20:52 +0800 Subject: [PATCH] =?UTF-8?q?=E7=99=BB=E9=99=86=E9=AA=8C=E8=AF=81=E5=8A=9F?= =?UTF-8?q?=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 1 - boot/boot.go | 10 +--------- config/config.toml | 15 +++++++++++++++ go.mod | 2 +- test/demo_test.go | 32 ++++++++++++++++++++++++++++++-- 5 files changed, 47 insertions(+), 13 deletions(-) create mode 100644 config/config.toml diff --git a/.gitignore b/.gitignore index 62624a8..980a6c4 100644 --- a/.gitignore +++ b/.gitignore @@ -15,7 +15,6 @@ pkg/ bin/ cbuild */.DS_Store -config/config.toml main .vscode go.sum diff --git a/boot/boot.go b/boot/boot.go index 0765cda..bfd7ce8 100644 --- a/boot/boot.go +++ b/boot/boot.go @@ -1,19 +1,11 @@ package boot import ( - "github.com/goflyfox/gtoken/gtoken" "github.com/gogf/gf/frame/g" ) func init() { g.Server().SetPort(8200) g.Server().AddStaticPath("/public", g.Cfg().Get("server.ServerRoot").(string)) - // 启动gtoken - gtoken := >oken.GfToken{ - LoginPath: "/login", - LoginBeforeFunc: loginFunc, - LogoutPath: "/user/logout", - AuthPaths: g.SliceStr{"/system/*"}, - } - gtoken.Start() + } diff --git a/config/config.toml b/config/config.toml new file mode 100644 index 0000000..f3e5c76 --- /dev/null +++ b/config/config.toml @@ -0,0 +1,15 @@ +# 数据库连接 +[database] + link = "mysql:root:123456@tcp(127.0.0.1:3306)/gfast" +#web服务器配置 +[server] + Address = ":8080" + ServerRoot = "./public/resource" + AccessLogEnabled = true + ErrorLogEnabled = true + PProfEnabled = true + LogPath = "./data/log/server_log" + SessionIdName = "sysSessionId" + SessionPath = "./data/session" + SessionMaxAge = "24h" + DumpRouterMap = true \ No newline at end of file diff --git a/go.mod b/go.mod index 3ada2d4..87e78de 100644 --- a/go.mod +++ b/go.mod @@ -2,7 +2,7 @@ module gfast require ( github.com/casbin/casbin/v2 v2.1.2 - github.com/goflyfox/gtoken v1.3.9 // indirect + github.com/goflyfox/gtoken v1.3.9 github.com/gogf/gf v1.10.1 github.com/mojocn/base64Captcha v1.2.2 ) diff --git a/test/demo_test.go b/test/demo_test.go index 8397437..5228aa0 100644 --- a/test/demo_test.go +++ b/test/demo_test.go @@ -5,6 +5,9 @@ import ( "gfast/library/utils" "github.com/casbin/casbin/v2" "github.com/casbin/casbin/v2/util" + "github.com/goflyfox/gtoken/gtoken" + "github.com/gogf/gf/frame/g" + "github.com/gogf/gf/net/ghttp" "github.com/gogf/gf/os/glog" "github.com/mojocn/base64Captcha" "testing" @@ -13,8 +16,9 @@ import ( func TestDemo(t *testing.T) { //t.Run("demo1" ,Demo1) //t.Run("Adapters_test", Adapters) - t.Run("CaptchaDemo", CaptchaDemo) - t.Run("CaptchaVerify", CaptchaVerify) + //t.Run("CaptchaDemo", CaptchaDemo) + //t.Run("CaptchaVerify", CaptchaVerify) + t.Run("GTokenTest", GTokenTest) } func Demo1(t *testing.T) { @@ -38,6 +42,30 @@ func Demo1(t *testing.T) { } } +func GTokenTest(t *testing.T) { + // 启动gtoken + gtoken := >oken.GfToken{ + LoginPath: "/login", + LoginBeforeFunc: loginFunc, + LogoutPath: "/user/logout", + AuthPaths: g.SliceStr{"/system/*"}, + LogoutBeforeFunc: loginOutFunc, + } + gtoken.Start() + s := g.Server() + s.BindHandler("/system/admin", func(r *ghttp.Request) { + r.Response.Write("hello admin") + }) + s.SetPort(8080) + s.Run() +} + +func loginFunc(r *ghttp.Request) (string, interface{}) { + return "yixiaohu", []g.MapStrStr{{"name": "张三", "age": "18"}, {"name": "李四", "age": "32"}} +} +func loginOutFunc(r *ghttp.Request) bool { + return true +} func demoCodeCaptchaCreate() { //config struct for digits //数字验证码配置