mirror of https://github.com/gofiber/fiber.git
🩹 draft for #1051
parent
c22107e2cc
commit
19bee02563
|
@ -1,6 +1,7 @@
|
|||
package gotiny
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"reflect"
|
||||
"sync"
|
||||
"time"
|
||||
|
@ -178,7 +179,8 @@ func buildDecEngine(rt reflect.Type, engPtr *decEng) {
|
|||
decString(d, unsafe.Pointer(&name))
|
||||
et, has := name2type[name]
|
||||
if !has {
|
||||
panic("unknown typ:" + name)
|
||||
//panic("unknown typ:" + name)
|
||||
fmt.Println("[session] Use the `RegisterType` option to decode this value.")
|
||||
}
|
||||
v := reflect.NewAt(rt, p).Elem()
|
||||
var ev reflect.Value
|
||||
|
@ -194,7 +196,7 @@ func buildDecEngine(rt reflect.Type, engPtr *decEng) {
|
|||
}
|
||||
}
|
||||
case reflect.Chan, reflect.Func:
|
||||
panic("not support " + rt.String() + " type")
|
||||
//panic("not support " + rt.String() + " type")
|
||||
default:
|
||||
engine = baseDecEngines[kind]
|
||||
}
|
||||
|
|
|
@ -187,7 +187,7 @@ func buildEncEngine(rt reflect.Type, engPtr *encEng) {
|
|||
}
|
||||
}
|
||||
case reflect.Chan, reflect.Func:
|
||||
panic("not support " + rt.String() + " type")
|
||||
//panic("not support " + rt.String() + " type")
|
||||
default:
|
||||
engine = encEngines[kind]
|
||||
}
|
||||
|
|
|
@ -44,6 +44,11 @@ type Config struct {
|
|||
// KeyGenerator generates the session key.
|
||||
// Optional. Default value utils.UUIDv4
|
||||
KeyGenerator func() string
|
||||
|
||||
// RegisterType allows you to store custom type/struct
|
||||
// in any Storage provider. Only use this option if you
|
||||
// are using custom a custom type/struct used as value.
|
||||
RegisterType interface{}
|
||||
}
|
||||
|
||||
// ConfigDefault is the default config
|
||||
|
|
|
@ -14,9 +14,6 @@ type Store struct {
|
|||
|
||||
var mux sync.Mutex
|
||||
|
||||
// Storage ErrNotExist
|
||||
var errNotExist = "key does not exist"
|
||||
|
||||
func New(config ...Config) *Store {
|
||||
// Set default config
|
||||
cfg := configDefault(config...)
|
||||
|
@ -24,6 +21,9 @@ func New(config ...Config) *Store {
|
|||
if cfg.Storage == nil {
|
||||
cfg.Storage = memory.New()
|
||||
}
|
||||
if cfg.RegisterType != nil {
|
||||
gotiny.Register(cfg.RegisterType)
|
||||
}
|
||||
|
||||
return &Store{
|
||||
cfg,
|
||||
|
|
Loading…
Reference in New Issue