From a01158850987a5ec98d2e6d39bdcef16395414b0 Mon Sep 17 00:00:00 2001 From: mountain Date: Thu, 31 Aug 2023 21:09:31 +0900 Subject: [PATCH] =?UTF-8?q?helper=20=ED=95=A8=EC=88=98=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- session/common.go | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/session/common.go b/session/common.go index 5850b37..7be9c41 100644 --- a/session/common.go +++ b/session/common.go @@ -82,6 +82,11 @@ func publickey_to_storagekey(pk publickey) storagekey { return storagekey(hex.EncodeToString(decoded[:])) } +type Config struct { + SessionTTL int64 `json:"session_ttl"` + SessionStorage string `json:"session_storage"` +} + var errInvalidScheme = errors.New("storageAddr is not valid scheme") func NewConsumer(ctx context.Context, storageAddr string, ttl time.Duration) (Consumer, error) { @@ -96,6 +101,10 @@ func NewConsumer(ctx context.Context, storageAddr string, ttl time.Duration) (Co return nil, errInvalidScheme } +func NewConsumerWithConfig(ctx context.Context, cfg Config) (Consumer, error) { + return NewConsumer(ctx, cfg.SessionStorage, time.Duration(cfg.SessionTTL)*time.Second) +} + func NewProvider(ctx context.Context, storageAddr string, ttl time.Duration) (Provider, error) { if strings.HasPrefix(storageAddr, "mongodb") { return newProviderWithMongo(ctx, storageAddr, ttl) @@ -108,7 +117,6 @@ func NewProvider(ctx context.Context, storageAddr string, ttl time.Duration) (Pr return nil, errInvalidScheme } -type Config struct { - SessionTTL int64 `json:"session_ttl"` - SessionStorage string `json:"session_storage"` +func NewProviderWithConfig(ctx context.Context, cfg Config) (Provider, error) { + return NewProvider(ctx, cfg.SessionStorage, time.Duration(cfg.SessionTTL)*time.Second) }