helper 함수 추가
This commit is contained in:
@ -82,6 +82,11 @@ func publickey_to_storagekey(pk publickey) storagekey {
|
|||||||
return storagekey(hex.EncodeToString(decoded[:]))
|
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")
|
var errInvalidScheme = errors.New("storageAddr is not valid scheme")
|
||||||
|
|
||||||
func NewConsumer(ctx context.Context, storageAddr string, ttl time.Duration) (Consumer, error) {
|
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
|
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) {
|
func NewProvider(ctx context.Context, storageAddr string, ttl time.Duration) (Provider, error) {
|
||||||
if strings.HasPrefix(storageAddr, "mongodb") {
|
if strings.HasPrefix(storageAddr, "mongodb") {
|
||||||
return newProviderWithMongo(ctx, storageAddr, ttl)
|
return newProviderWithMongo(ctx, storageAddr, ttl)
|
||||||
@ -108,7 +117,6 @@ func NewProvider(ctx context.Context, storageAddr string, ttl time.Duration) (Pr
|
|||||||
return nil, errInvalidScheme
|
return nil, errInvalidScheme
|
||||||
}
|
}
|
||||||
|
|
||||||
type Config struct {
|
func NewProviderWithConfig(ctx context.Context, cfg Config) (Provider, error) {
|
||||||
SessionTTL int64 `json:"session_ttl"`
|
return NewProvider(ctx, cfg.SessionStorage, time.Duration(cfg.SessionTTL)*time.Second)
|
||||||
SessionStorage string `json:"session_storage"`
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user