오류 처리 추가

This commit is contained in:
2023-08-31 21:16:19 +09:00
parent 90502c3029
commit 9e9d91b5a3

View File

@ -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)
}