mirror of https://github.com/gofiber/fiber.git
🌀 introduce RegisterType
parent
65598c2831
commit
0fe30ac722
|
@ -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
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
Loading…
Reference in New Issue