diff --git a/session/common.go b/session/common.go index 3694020..ddd8c21 100644 --- a/session/common.go +++ b/session/common.go @@ -88,6 +88,7 @@ type SessionConfig struct { } var errInvalidScheme = errors.New("storageAddr is not valid scheme") +var errSessionStorageMissing = errors.New("session_storageis missing") func NewConsumer(ctx context.Context, storageAddr string, ttl time.Duration) (Consumer, error) { if strings.HasPrefix(storageAddr, "mongodb") { @@ -102,6 +103,13 @@ func NewConsumer(ctx context.Context, storageAddr string, ttl time.Duration) (Co } func NewConsumerWithConfig(ctx context.Context, cfg SessionConfig) (Consumer, error) { + if len(cfg.SessionStorage) == 0 { + return nil, errSessionStorageMissing + } + + if cfg.SessionTTL == 0 { + cfg.SessionTTL = 3600 + } return NewConsumer(ctx, cfg.SessionStorage, time.Duration(cfg.SessionTTL)*time.Second) } @@ -118,5 +126,12 @@ func NewProvider(ctx context.Context, storageAddr string, ttl time.Duration) (Pr } func NewProviderWithConfig(ctx context.Context, cfg SessionConfig) (Provider, error) { + if len(cfg.SessionStorage) == 0 { + return nil, errSessionStorageMissing + } + + if cfg.SessionTTL == 0 { + cfg.SessionTTL = 3600 + } return NewProvider(ctx, cfg.SessionStorage, time.Duration(cfg.SessionTTL)*time.Second) }