From 9e9d91b5a30fee1372b85cd0d53317950ba75bd7 Mon Sep 17 00:00:00 2001 From: mountain Date: Thu, 31 Aug 2023 21:16:19 +0900 Subject: [PATCH] =?UTF-8?q?=EC=98=A4=EB=A5=98=20=EC=B2=98=EB=A6=AC=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- session/common.go | 15 +++++++++++++++ 1 file changed, 15 insertions(+) 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) }