consumer, provider 생성 방법 통일
This commit is contained in:
@ -1,9 +1,12 @@
|
||||
package session
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/binary"
|
||||
"encoding/hex"
|
||||
"errors"
|
||||
"math/rand"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"go.mongodb.org/mongo-driver/bson/primitive"
|
||||
@ -78,3 +81,29 @@ func publickey_to_storagekey(pk publickey) storagekey {
|
||||
|
||||
return storagekey(hex.EncodeToString(decoded[:]))
|
||||
}
|
||||
|
||||
var errInvalidScheme = errors.New("storageAddr is not valid scheme")
|
||||
|
||||
func NewConsumer(ctx context.Context, storageAddr string, ttl time.Duration) (Consumer, error) {
|
||||
if strings.HasPrefix(storageAddr, "mongodb") {
|
||||
return newConsumerWithMongo(ctx, storageAddr, ttl)
|
||||
}
|
||||
|
||||
if strings.HasPrefix(storageAddr, "redis") {
|
||||
return newConsumerWithRedis(ctx, storageAddr, ttl)
|
||||
}
|
||||
|
||||
return nil, errInvalidScheme
|
||||
}
|
||||
|
||||
func NewProvider(ctx context.Context, storageAddr string, ttl time.Duration) (Provider, error) {
|
||||
if strings.HasPrefix(storageAddr, "mongodb") {
|
||||
return newProviderWithMongo(ctx, storageAddr, ttl)
|
||||
}
|
||||
|
||||
if strings.HasPrefix(storageAddr, "redis") {
|
||||
return newProviderWithRedis(ctx, storageAddr, ttl)
|
||||
}
|
||||
|
||||
return nil, errInvalidScheme
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user