🌀 introduce RegisterType

pull/1054/head
Fenny 2020-12-06 16:37:08 +01:00
parent 65598c2831
commit 0fe30ac722
3 changed files with 10 additions and 5 deletions

View File

@ -11,6 +11,7 @@ Session middleware for [Fiber](https://github.com/gofiber/fiber)
### Signatures
```go
func New(config ...Config) *Store
func (s *Store) RegisterType(i interface{})
func (s *Store) Get(c *fiber.Ctx) (*Session, error)
func (s *Store) Reset() error

View File

@ -45,10 +45,10 @@ type Config struct {
// Optional. Default value utils.UUIDv4
KeyGenerator func() string
// RegisterType allows you to store custom type/struct
// CustomType 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{}
CustomType interface{}
}
// ConfigDefault is the default config

View File

@ -21,15 +21,19 @@ func New(config ...Config) *Store {
if cfg.Storage == nil {
cfg.Storage = memory.New()
}
if cfg.RegisterType != nil {
gotiny.Register(cfg.RegisterType)
}
return &Store{
cfg,
}
}
// RegisterType will allow you to encode/decode custom types
// into any Storage provider
func (s *Store) RegisterType(i interface{}) {
gotiny.Register(i)
}
// Get will get/create a session
func (s *Store) Get(c *fiber.Ctx) (*Session, error) {
var fresh bool