helper 함수 추가
This commit is contained in:
@ -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)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user