🩹 draft for #1051

pull/1054/head
Fenny 2020-12-03 11:56:32 +01:00
parent c22107e2cc
commit 19bee02563
4 changed files with 13 additions and 6 deletions

View File

@ -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]
}

View File

@ -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]
}

View File

@ -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

View File

@ -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,