mirror of
https://github.com/quarkcloudio/quark-go.git
synced 2025-09-26 20:11:11 +08:00
feat: casbin支持redis存储
This commit is contained in:
@@ -38,6 +38,12 @@ func main() {
|
|||||||
Dialector: mysql.Open(dsn),
|
Dialector: mysql.Open(dsn),
|
||||||
Opts: &gorm.Config{},
|
Opts: &gorm.Config{},
|
||||||
},
|
},
|
||||||
|
RedisConfig: &builder.RedisConfig{
|
||||||
|
Host: "127.0.0.1",
|
||||||
|
Port: "6379",
|
||||||
|
Password: "",
|
||||||
|
Database: 0,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
// 实例化对象
|
// 实例化对象
|
||||||
|
7
go.mod
7
go.mod
@@ -11,13 +11,14 @@ require (
|
|||||||
github.com/cloudwego/hertz v0.6.6
|
github.com/cloudwego/hertz v0.6.6
|
||||||
github.com/dchest/captcha v1.0.0
|
github.com/dchest/captcha v1.0.0
|
||||||
github.com/derekstavis/go-qs v0.0.0-20180720192143-9eef69e6c4e7
|
github.com/derekstavis/go-qs v0.0.0-20180720192143-9eef69e6c4e7
|
||||||
|
github.com/gabriel-vasile/mimetype v1.4.2
|
||||||
github.com/gin-contrib/static v0.0.1
|
github.com/gin-contrib/static v0.0.1
|
||||||
github.com/go-basic/uuid v1.0.0
|
github.com/go-basic/uuid v1.0.0
|
||||||
github.com/go-redis/redis/v8 v8.11.5
|
|
||||||
github.com/gobeam/stringy v0.0.6
|
github.com/gobeam/stringy v0.0.6
|
||||||
github.com/gofiber/fiber/v2 v2.47.0
|
github.com/gofiber/fiber/v2 v2.47.0
|
||||||
github.com/golang-jwt/jwt/v4 v4.5.0
|
github.com/golang-jwt/jwt/v4 v4.5.0
|
||||||
github.com/parnurzeal/gorequest v0.2.16
|
github.com/parnurzeal/gorequest v0.2.16
|
||||||
|
github.com/redis/go-redis/v9 v9.0.3
|
||||||
github.com/shirou/gopsutil v3.21.11+incompatible
|
github.com/shirou/gopsutil v3.21.11+incompatible
|
||||||
github.com/xuri/excelize/v2 v2.7.1
|
github.com/xuri/excelize/v2 v2.7.1
|
||||||
golang.org/x/crypto v0.14.0
|
golang.org/x/crypto v0.14.0
|
||||||
@@ -33,7 +34,6 @@ require (
|
|||||||
github.com/cenkalti/backoff/v4 v4.2.1 // indirect
|
github.com/cenkalti/backoff/v4 v4.2.1 // indirect
|
||||||
github.com/dustin/go-humanize v1.0.1 // indirect
|
github.com/dustin/go-humanize v1.0.1 // indirect
|
||||||
github.com/fatih/color v1.15.0 // indirect
|
github.com/fatih/color v1.15.0 // indirect
|
||||||
github.com/gabriel-vasile/mimetype v1.4.2 // indirect
|
|
||||||
github.com/gin-contrib/sse v0.1.0 // indirect
|
github.com/gin-contrib/sse v0.1.0 // indirect
|
||||||
github.com/glebarez/go-sqlite v1.21.2 // indirect
|
github.com/glebarez/go-sqlite v1.21.2 // indirect
|
||||||
github.com/glebarez/sqlite v1.9.0 // indirect
|
github.com/glebarez/sqlite v1.9.0 // indirect
|
||||||
@@ -121,6 +121,7 @@ require (
|
|||||||
github.com/bytedance/gopkg v0.0.0-20230531144706-a12972768317 // indirect
|
github.com/bytedance/gopkg v0.0.0-20230531144706-a12972768317 // indirect
|
||||||
github.com/bytedance/sonic v1.9.2 // indirect
|
github.com/bytedance/sonic v1.9.2 // indirect
|
||||||
github.com/casbin/gorm-adapter/v3 v3.18.0
|
github.com/casbin/gorm-adapter/v3 v3.18.0
|
||||||
|
github.com/casbin/redis-watcher/v2 v2.5.0
|
||||||
github.com/cespare/xxhash/v2 v2.2.0 // indirect
|
github.com/cespare/xxhash/v2 v2.2.0 // indirect
|
||||||
github.com/chenzhuoyu/base64x v0.0.0-20221115062448-fe3a3abad311 // indirect
|
github.com/chenzhuoyu/base64x v0.0.0-20221115062448-fe3a3abad311 // indirect
|
||||||
github.com/clbanning/mxj/v2 v2.5.7 // indirect
|
github.com/clbanning/mxj/v2 v2.5.7 // indirect
|
||||||
@@ -135,7 +136,6 @@ require (
|
|||||||
github.com/golang/protobuf v1.5.3 // indirect
|
github.com/golang/protobuf v1.5.3 // indirect
|
||||||
github.com/gookit/goutil v0.6.11
|
github.com/gookit/goutil v0.6.11
|
||||||
github.com/gorilla/sessions v1.2.2
|
github.com/gorilla/sessions v1.2.2
|
||||||
github.com/h2non/filetype v1.1.3
|
|
||||||
github.com/jinzhu/inflection v1.0.0 // indirect
|
github.com/jinzhu/inflection v1.0.0 // indirect
|
||||||
github.com/jinzhu/now v1.1.5 // indirect
|
github.com/jinzhu/now v1.1.5 // indirect
|
||||||
github.com/json-iterator/go v1.1.12 // indirect
|
github.com/json-iterator/go v1.1.12 // indirect
|
||||||
@@ -164,7 +164,6 @@ require (
|
|||||||
github.com/valyala/bytebufferpool v1.0.0 // indirect
|
github.com/valyala/bytebufferpool v1.0.0 // indirect
|
||||||
github.com/valyala/fasthttp v1.48.0 // indirect
|
github.com/valyala/fasthttp v1.48.0 // indirect
|
||||||
github.com/valyala/tcplisten v1.0.0 // indirect
|
github.com/valyala/tcplisten v1.0.0 // indirect
|
||||||
github.com/xbmlz/gct v0.0.0-20220707064702-998631a80a6a
|
|
||||||
github.com/xuri/efp v0.0.0-20230422071738-01f4e37c47e9 // indirect
|
github.com/xuri/efp v0.0.0-20230422071738-01f4e37c47e9 // indirect
|
||||||
github.com/xuri/nfp v0.0.0-20230503010013-3f38cdbb0b83 // indirect
|
github.com/xuri/nfp v0.0.0-20230503010013-3f38cdbb0b83 // indirect
|
||||||
github.com/yusufpapurcu/wmi v1.2.3 // indirect
|
github.com/yusufpapurcu/wmi v1.2.3 // indirect
|
||||||
|
10
go.sum
10
go.sum
@@ -51,6 +51,8 @@ github.com/andybalholm/brotli v1.0.5 h1:8uQZIdzKmjc/iuPu7O2ioW48L81FgatrcpfFmiq/
|
|||||||
github.com/andybalholm/brotli v1.0.5/go.mod h1:fO7iG3H7G2nSZ7m0zPUDn85XEX2GTukHGRSepvi9Eig=
|
github.com/andybalholm/brotli v1.0.5/go.mod h1:fO7iG3H7G2nSZ7m0zPUDn85XEX2GTukHGRSepvi9Eig=
|
||||||
github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM=
|
github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM=
|
||||||
github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw=
|
github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw=
|
||||||
|
github.com/bsm/ginkgo/v2 v2.7.0 h1:ItPMPH90RbmZJt5GtkcNvIRuGEdwlBItdNVoyzaNQao=
|
||||||
|
github.com/bsm/gomega v1.26.0 h1:LhQm+AFcgV2M0WyKroMASzAzCAJVpAxQXv4SaI9a69Y=
|
||||||
github.com/bytedance/go-tagexpr/v2 v2.9.2/go.mod h1:5qsx05dYOiUXOUgnQ7w3Oz8BYs2qtM/bJokdLb79wRM=
|
github.com/bytedance/go-tagexpr/v2 v2.9.2/go.mod h1:5qsx05dYOiUXOUgnQ7w3Oz8BYs2qtM/bJokdLb79wRM=
|
||||||
github.com/bytedance/go-tagexpr/v2 v2.9.8 h1:p1PWxiUPxAdzreRBRbC9M2k7tf1cZYkds58NLypXbg4=
|
github.com/bytedance/go-tagexpr/v2 v2.9.8 h1:p1PWxiUPxAdzreRBRbC9M2k7tf1cZYkds58NLypXbg4=
|
||||||
github.com/bytedance/go-tagexpr/v2 v2.9.8/go.mod h1:UAyKh4ZRLBPGsyTRFZoPqTni1TlojMdOJXQnEIPCX84=
|
github.com/bytedance/go-tagexpr/v2 v2.9.8/go.mod h1:UAyKh4ZRLBPGsyTRFZoPqTni1TlojMdOJXQnEIPCX84=
|
||||||
@@ -67,6 +69,8 @@ github.com/casbin/casbin/v2 v2.71.1 h1:LRHyqM0S1LzM/K59PmfUIN0ZJfLgcOjL4OhOQI/FN
|
|||||||
github.com/casbin/casbin/v2 v2.71.1/go.mod h1:vByNa/Fchek0KZUgG5wEsl7iFsiviAYKRtgrQfcJqHg=
|
github.com/casbin/casbin/v2 v2.71.1/go.mod h1:vByNa/Fchek0KZUgG5wEsl7iFsiviAYKRtgrQfcJqHg=
|
||||||
github.com/casbin/gorm-adapter/v3 v3.18.0 h1:0td7v030eK3H5ftXRHx1d5wVPbuYEJP2ObMSUHtA0Ek=
|
github.com/casbin/gorm-adapter/v3 v3.18.0 h1:0td7v030eK3H5ftXRHx1d5wVPbuYEJP2ObMSUHtA0Ek=
|
||||||
github.com/casbin/gorm-adapter/v3 v3.18.0/go.mod h1:ekufPNBgVIQvv9JffVGsg7KUv4DjnevTh6AQnBNkoK8=
|
github.com/casbin/gorm-adapter/v3 v3.18.0/go.mod h1:ekufPNBgVIQvv9JffVGsg7KUv4DjnevTh6AQnBNkoK8=
|
||||||
|
github.com/casbin/redis-watcher/v2 v2.5.0 h1:a0922GOKYDSSiD7hEQxmLh/psea2eLZtf1V12XzLI5w=
|
||||||
|
github.com/casbin/redis-watcher/v2 v2.5.0/go.mod h1:lgtjnQrfbo+xZIwMPtLu9is/XpnCfAT94SLgMzY7HGk=
|
||||||
github.com/cenkalti/backoff/v4 v4.2.1 h1:y4OZtCnogmCPw98Zjyt5a6+QwPLGkiQsYW5oUqylYbM=
|
github.com/cenkalti/backoff/v4 v4.2.1 h1:y4OZtCnogmCPw98Zjyt5a6+QwPLGkiQsYW5oUqylYbM=
|
||||||
github.com/cenkalti/backoff/v4 v4.2.1/go.mod h1:Y3VNntkOUPxTVeUxJ/G5vcM//AlwfmyYozVcomhLiZE=
|
github.com/cenkalti/backoff/v4 v4.2.1/go.mod h1:Y3VNntkOUPxTVeUxJ/G5vcM//AlwfmyYozVcomhLiZE=
|
||||||
github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU=
|
github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU=
|
||||||
@@ -213,8 +217,6 @@ github.com/gorilla/sessions v1.2.2 h1:lqzMYz6bOfvn2WriPUjNByzeXIlVzURcPmgMczkmTj
|
|||||||
github.com/gorilla/sessions v1.2.2/go.mod h1:ePLdVu+jbEgHH+KWw8I1z2wqd0BAdAQh/8LRvBeoNcQ=
|
github.com/gorilla/sessions v1.2.2/go.mod h1:ePLdVu+jbEgHH+KWw8I1z2wqd0BAdAQh/8LRvBeoNcQ=
|
||||||
github.com/grpc-ecosystem/grpc-gateway/v2 v2.16.0 h1:YBftPWNWd4WwGqtY2yeZL2ef8rHAxPBD8KFhJpmcqms=
|
github.com/grpc-ecosystem/grpc-gateway/v2 v2.16.0 h1:YBftPWNWd4WwGqtY2yeZL2ef8rHAxPBD8KFhJpmcqms=
|
||||||
github.com/grpc-ecosystem/grpc-gateway/v2 v2.16.0/go.mod h1:YN5jB8ie0yfIUg6VvR9Kz84aCaG7AsGZnLjhHbUqwPg=
|
github.com/grpc-ecosystem/grpc-gateway/v2 v2.16.0/go.mod h1:YN5jB8ie0yfIUg6VvR9Kz84aCaG7AsGZnLjhHbUqwPg=
|
||||||
github.com/h2non/filetype v1.1.3 h1:FKkx9QbD7HR/zjK1Ia5XiBsq9zdLi5Kf3zGyFTAFkGg=
|
|
||||||
github.com/h2non/filetype v1.1.3/go.mod h1:319b3zT68BvV+WRj7cwy856M2ehB3HqNOt6sy1HndBY=
|
|
||||||
github.com/h2non/parth v0.0.0-20190131123155-b4df798d6542 h1:2VTzZjLZBgl62/EtslCrtky5vbi9dd7HrQPQIx6wqiw=
|
github.com/h2non/parth v0.0.0-20190131123155-b4df798d6542 h1:2VTzZjLZBgl62/EtslCrtky5vbi9dd7HrQPQIx6wqiw=
|
||||||
github.com/hashicorp/go-uuid v1.0.2/go.mod h1:6SBZvOh/SIDV7/2o3Jml5SYk/TvGqwFJ/bN7x4byOro=
|
github.com/hashicorp/go-uuid v1.0.2/go.mod h1:6SBZvOh/SIDV7/2o3Jml5SYk/TvGqwFJ/bN7x4byOro=
|
||||||
github.com/hashicorp/go-uuid v1.0.3/go.mod h1:6SBZvOh/SIDV7/2o3Jml5SYk/TvGqwFJ/bN7x4byOro=
|
github.com/hashicorp/go-uuid v1.0.3/go.mod h1:6SBZvOh/SIDV7/2o3Jml5SYk/TvGqwFJ/bN7x4byOro=
|
||||||
@@ -330,6 +332,8 @@ github.com/prometheus/common v0.44.0 h1:+5BrQJwiBB9xsMygAB3TNvpQKOwlkc25LbISbrdO
|
|||||||
github.com/prometheus/common v0.44.0/go.mod h1:ofAIvZbQ1e/nugmZGz4/qCb9Ap1VoSTIO7x0VV9VvuY=
|
github.com/prometheus/common v0.44.0/go.mod h1:ofAIvZbQ1e/nugmZGz4/qCb9Ap1VoSTIO7x0VV9VvuY=
|
||||||
github.com/prometheus/procfs v0.11.0 h1:5EAgkfkMl659uZPbe9AS2N68a7Cc1TJbPEuGzFuRbyk=
|
github.com/prometheus/procfs v0.11.0 h1:5EAgkfkMl659uZPbe9AS2N68a7Cc1TJbPEuGzFuRbyk=
|
||||||
github.com/prometheus/procfs v0.11.0/go.mod h1:nwNm2aOCAYw8uTR/9bWRREkZFxAUcWzPHWJq+XBB/FM=
|
github.com/prometheus/procfs v0.11.0/go.mod h1:nwNm2aOCAYw8uTR/9bWRREkZFxAUcWzPHWJq+XBB/FM=
|
||||||
|
github.com/redis/go-redis/v9 v9.0.3 h1:+7mmR26M0IvyLxGZUHxu4GiBkJkVDid0Un+j4ScYu4k=
|
||||||
|
github.com/redis/go-redis/v9 v9.0.3/go.mod h1:WqMKv5vnQbRuZstUwxQI195wHy+t4PuXDOjzMvcuQHk=
|
||||||
github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec h1:W09IVJc94icq4NjY3clb7Lk8O1qJ8BdBEF8z0ibU0rE=
|
github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec h1:W09IVJc94icq4NjY3clb7Lk8O1qJ8BdBEF8z0ibU0rE=
|
||||||
github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec/go.mod h1:qqbHyh8v60DhA7CoWK5oRCqLrMHRGoxYCSS9EjAz6Eo=
|
github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec/go.mod h1:qqbHyh8v60DhA7CoWK5oRCqLrMHRGoxYCSS9EjAz6Eo=
|
||||||
github.com/richardlehane/mscfb v1.0.4 h1:WULscsljNPConisD5hR0+OyZjwK46Pfyr6mPu5ZawpM=
|
github.com/richardlehane/mscfb v1.0.4 h1:WULscsljNPConisD5hR0+OyZjwK46Pfyr6mPu5ZawpM=
|
||||||
@@ -409,8 +413,6 @@ github.com/valyala/fasttemplate v1.2.2 h1:lxLXG0uE3Qnshl9QyaK6XJxMXlQZELvChBOCmQ
|
|||||||
github.com/valyala/fasttemplate v1.2.2/go.mod h1:KHLXt3tVN2HBp8eijSv/kGJopbvo7S+qRAEEKiv+SiQ=
|
github.com/valyala/fasttemplate v1.2.2/go.mod h1:KHLXt3tVN2HBp8eijSv/kGJopbvo7S+qRAEEKiv+SiQ=
|
||||||
github.com/valyala/tcplisten v1.0.0 h1:rBHj/Xf+E1tRGZyWIWwJDiRY0zc1Js+CV5DqwacVSA8=
|
github.com/valyala/tcplisten v1.0.0 h1:rBHj/Xf+E1tRGZyWIWwJDiRY0zc1Js+CV5DqwacVSA8=
|
||||||
github.com/valyala/tcplisten v1.0.0/go.mod h1:T0xQ8SeCZGxckz9qRXTfG43PvQ/mcWh7FwZEA7Ioqkc=
|
github.com/valyala/tcplisten v1.0.0/go.mod h1:T0xQ8SeCZGxckz9qRXTfG43PvQ/mcWh7FwZEA7Ioqkc=
|
||||||
github.com/xbmlz/gct v0.0.0-20220707064702-998631a80a6a h1:trfL4gldWsl4RdXVft2j8VZu4Xh+sws7EovGTJyfnOs=
|
|
||||||
github.com/xbmlz/gct v0.0.0-20220707064702-998631a80a6a/go.mod h1:45Nbht0AaBjpcsN2z0Zr67vCcfeA12mM7BrtEIVCh90=
|
|
||||||
github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e h1:JVG44RsyaB9T2KIHavMF/ppJZNG9ZpyihvCd0w101no=
|
github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e h1:JVG44RsyaB9T2KIHavMF/ppJZNG9ZpyihvCd0w101no=
|
||||||
github.com/xuri/efp v0.0.0-20220603152613-6918739fd470/go.mod h1:ybY/Jr0T0GTCnYjKqmdwxyxn2BQf2RcQIIvex5QldPI=
|
github.com/xuri/efp v0.0.0-20220603152613-6918739fd470/go.mod h1:ybY/Jr0T0GTCnYjKqmdwxyxn2BQf2RcQIIvex5QldPI=
|
||||||
github.com/xuri/efp v0.0.0-20230422071738-01f4e37c47e9 h1:ge5g8vsTQclA5lXDi+PuiAFw5GMIlMHOB/5e1hsf96E=
|
github.com/xuri/efp v0.0.0-20230422071738-01f4e37c47e9 h1:ge5g8vsTQclA5lXDi+PuiAFw5GMIlMHOB/5e1hsf96E=
|
||||||
|
@@ -7,7 +7,10 @@ import (
|
|||||||
"github.com/casbin/casbin/v2"
|
"github.com/casbin/casbin/v2"
|
||||||
casbinmodel "github.com/casbin/casbin/v2/model"
|
casbinmodel "github.com/casbin/casbin/v2/model"
|
||||||
gormadapter "github.com/casbin/gorm-adapter/v3"
|
gormadapter "github.com/casbin/gorm-adapter/v3"
|
||||||
|
rediswatcher "github.com/casbin/redis-watcher/v2"
|
||||||
|
"github.com/quarkcloudio/quark-go/v2/pkg/builder"
|
||||||
"github.com/quarkcloudio/quark-go/v2/pkg/dal/db"
|
"github.com/quarkcloudio/quark-go/v2/pkg/dal/db"
|
||||||
|
"github.com/redis/go-redis/v9"
|
||||||
)
|
)
|
||||||
|
|
||||||
// 字段
|
// 字段
|
||||||
@@ -59,6 +62,28 @@ func (p *CasbinRule) Enforcer() (enforcer *casbin.Enforcer, err error) {
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
redisConfig := builder.GetConfig().RedisConfig
|
||||||
|
if redisConfig != nil {
|
||||||
|
w, _ := rediswatcher.NewWatcher(redisConfig.Host+":"+redisConfig.Port, rediswatcher.WatcherOptions{
|
||||||
|
Options: redis.Options{
|
||||||
|
Network: "tcp",
|
||||||
|
Password: redisConfig.Password,
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
// Set the watcher for the enforcer.
|
||||||
|
err = Enforcer.SetWatcher(w)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
// Or use the default callback
|
||||||
|
err = w.SetUpdateCallback(rediswatcher.DefaultUpdateCallback(Enforcer))
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return Enforcer, err
|
return Enforcer, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -4,7 +4,7 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/go-redis/redis/v8"
|
"github.com/redis/go-redis/v9"
|
||||||
)
|
)
|
||||||
|
|
||||||
type CaptchaStore struct {
|
type CaptchaStore struct {
|
||||||
|
@@ -50,6 +50,14 @@ func (p *Template) TemplateInit(ctx *builder.Context) interface{} {
|
|||||||
// 子标题
|
// 子标题
|
||||||
p.SubTitle = "信息丰富的世界里,唯一稀缺的就是人类的注意力"
|
p.SubTitle = "信息丰富的世界里,唯一稀缺的就是人类的注意力"
|
||||||
|
|
||||||
|
// 如果启动了redis缓存,验证码使用redis缓存
|
||||||
|
if redisclient.Client != nil {
|
||||||
|
captcha.SetCustomStore(&CaptchaStore{
|
||||||
|
RedisClient: redisclient.Client,
|
||||||
|
Expiration: time.Second * 1000,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
return p
|
return p
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -89,16 +97,6 @@ func (p *Template) GetSubTitle() string {
|
|||||||
return p.SubTitle
|
return p.SubTitle
|
||||||
}
|
}
|
||||||
|
|
||||||
// 验证码存储驱动,redis | memory
|
|
||||||
func (p *Template) CaptchaStore(store string) {
|
|
||||||
if store == "redis" {
|
|
||||||
captcha.SetCustomStore(&CaptchaStore{
|
|
||||||
RedisClient: redisclient.Client,
|
|
||||||
Expiration: time.Second * 1000,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// 验证码ID
|
// 验证码ID
|
||||||
func (p *Template) CaptchaId(ctx *builder.Context) error {
|
func (p *Template) CaptchaId(ctx *builder.Context) error {
|
||||||
|
|
||||||
|
@@ -22,9 +22,6 @@ type Loginer interface {
|
|||||||
// 获取登录页面子标题
|
// 获取登录页面子标题
|
||||||
GetSubTitle() string
|
GetSubTitle() string
|
||||||
|
|
||||||
// 验证码存储驱动,redis | memory
|
|
||||||
CaptchaStore(store string)
|
|
||||||
|
|
||||||
// 验证码ID
|
// 验证码ID
|
||||||
CaptchaId(ctx *builder.Context) error
|
CaptchaId(ctx *builder.Context) error
|
||||||
|
|
||||||
|
@@ -7,12 +7,12 @@ import (
|
|||||||
"runtime"
|
"runtime"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/go-redis/redis/v8"
|
|
||||||
"github.com/gorilla/sessions"
|
"github.com/gorilla/sessions"
|
||||||
"github.com/labstack/echo/v4"
|
"github.com/labstack/echo/v4"
|
||||||
"github.com/quarkcloudio/quark-go/v2/pkg/dal"
|
"github.com/quarkcloudio/quark-go/v2/pkg/dal"
|
||||||
"github.com/quarkcloudio/quark-go/v2/pkg/gopkg"
|
"github.com/quarkcloudio/quark-go/v2/pkg/gopkg"
|
||||||
"github.com/quarkcloudio/quark-go/v2/pkg/utils/file"
|
"github.com/quarkcloudio/quark-go/v2/pkg/utils/file"
|
||||||
|
"github.com/redis/go-redis/v9"
|
||||||
"gorm.io/gorm"
|
"gorm.io/gorm"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -22,7 +22,7 @@ const (
|
|||||||
AppName = "QuarkGo"
|
AppName = "QuarkGo"
|
||||||
|
|
||||||
// 版本号
|
// 版本号
|
||||||
Version = "2.2.10"
|
Version = "2.3.0"
|
||||||
|
|
||||||
// 包名
|
// 包名
|
||||||
PkgName = "github.com/quarkcloudio/quark-go/v2"
|
PkgName = "github.com/quarkcloudio/quark-go/v2"
|
||||||
@@ -79,8 +79,15 @@ type Group struct {
|
|||||||
// 定义路由方法类型
|
// 定义路由方法类型
|
||||||
type Handle func(ctx *Context) error
|
type Handle func(ctx *Context) error
|
||||||
|
|
||||||
|
// 全局配置
|
||||||
|
var AppConfig *Config
|
||||||
|
|
||||||
// 初始化对象
|
// 初始化对象
|
||||||
func New(config *Config) *Engine {
|
func New(config *Config) *Engine {
|
||||||
|
|
||||||
|
// 初始化应用配置
|
||||||
|
AppConfig = config
|
||||||
|
|
||||||
// 初始化echo引擎
|
// 初始化echo引擎
|
||||||
e := echo.New()
|
e := echo.New()
|
||||||
|
|
||||||
@@ -136,6 +143,11 @@ func New(config *Config) *Engine {
|
|||||||
return engine
|
return engine
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 获取当前配置
|
||||||
|
func GetConfig() *Config {
|
||||||
|
return AppConfig
|
||||||
|
}
|
||||||
|
|
||||||
// 获取当前配置
|
// 获取当前配置
|
||||||
func (p *Engine) GetConfig() *Config {
|
func (p *Engine) GetConfig() *Config {
|
||||||
return p.config
|
return p.config
|
||||||
|
@@ -1,9 +1,9 @@
|
|||||||
package dal
|
package dal
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/go-redis/redis/v8"
|
|
||||||
"github.com/quarkcloudio/quark-go/v2/pkg/dal/db"
|
"github.com/quarkcloudio/quark-go/v2/pkg/dal/db"
|
||||||
redisclient "github.com/quarkcloudio/quark-go/v2/pkg/dal/redis"
|
redisclient "github.com/quarkcloudio/quark-go/v2/pkg/dal/redis"
|
||||||
|
"github.com/redis/go-redis/v9"
|
||||||
"gorm.io/gorm"
|
"gorm.io/gorm"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@@ -3,7 +3,7 @@ package redis
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
|
||||||
"github.com/go-redis/redis/v8"
|
"github.com/redis/go-redis/v9"
|
||||||
)
|
)
|
||||||
|
|
||||||
var Client *redis.Client
|
var Client *redis.Client
|
||||||
|
Reference in New Issue
Block a user