Compare commits
2 Commits
Author | SHA1 | Date |
---|---|---|
|
fb585fabe6 | |
|
29d609ce0a |
|
@ -57,9 +57,16 @@ func WithAllow(paths ...string) Option {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func WithClaims(claims reflect.Type) Option {
|
func WithClaims(claims any) Option {
|
||||||
return func(o *options) {
|
return func(o *options) {
|
||||||
o.claims = claims
|
if tv, ok := claims.(reflect.Type); ok {
|
||||||
|
o.claims = tv
|
||||||
|
} else {
|
||||||
|
o.claims = reflect.TypeOf(claims)
|
||||||
|
if o.claims.Kind() == reflect.Ptr {
|
||||||
|
o.claims = o.claims.Elem()
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -4,6 +4,8 @@ import (
|
||||||
"context"
|
"context"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"git.nobla.cn/golang/aeus"
|
||||||
)
|
)
|
||||||
|
|
||||||
type redisCache struct {
|
type redisCache struct {
|
||||||
|
@ -57,7 +59,12 @@ func (c *redisCache) String() string {
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewCache(opts ...Option) *redisCache {
|
func NewCache(opts ...Option) *redisCache {
|
||||||
return &redisCache{
|
cache := &redisCache{
|
||||||
opts: newOptions(opts...),
|
opts: newOptions(opts...),
|
||||||
}
|
}
|
||||||
|
app := aeus.FromContext(cache.opts.context)
|
||||||
|
if app != nil {
|
||||||
|
cache.opts.prefix = app.Name() + ":" + cache.opts.prefix
|
||||||
|
}
|
||||||
|
return cache
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,13 +1,16 @@
|
||||||
package redis
|
package redis
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
|
|
||||||
"github.com/redis/go-redis/v9"
|
"github.com/redis/go-redis/v9"
|
||||||
)
|
)
|
||||||
|
|
||||||
type (
|
type (
|
||||||
options struct {
|
options struct {
|
||||||
client *redis.Client
|
context context.Context
|
||||||
prefix string
|
client *redis.Client
|
||||||
|
prefix string
|
||||||
}
|
}
|
||||||
|
|
||||||
Option func(*options)
|
Option func(*options)
|
||||||
|
@ -19,6 +22,12 @@ func WithClient(client *redis.Client) Option {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func WithContext(ctx context.Context) Option {
|
||||||
|
return func(o *options) {
|
||||||
|
o.context = ctx
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func WithPrefix(prefix string) Option {
|
func WithPrefix(prefix string) Option {
|
||||||
return func(o *options) {
|
return func(o *options) {
|
||||||
o.prefix = prefix
|
o.prefix = prefix
|
||||||
|
|
Loading…
Reference in New Issue