Documentation ¶
Index ¶
- Constants
- Variables
- type ListMongoLockIterator
- type MongoConnectionManager
- type MongoLock
- type MongoStorage
- func (x *MongoStorage) Close(ctx context.Context) error
- func (x *MongoStorage) CreateWithVersion(ctx context.Context, lockId string, version storage.Version, ...) error
- func (x *MongoStorage) DeleteWithVersion(ctx context.Context, lockId string, exceptedVersion storage.Version, ...) error
- func (x *MongoStorage) Get(ctx context.Context, lockId string) (string, error)
- func (x *MongoStorage) GetName() string
- func (x *MongoStorage) GetTime(ctx context.Context) (time.Time, error)
- func (x *MongoStorage) Init(ctx context.Context) error
- func (x *MongoStorage) List(ctx context.Context) (iterator.Iterator[*storage.LockInformation], error)
- func (x *MongoStorage) UpdateWithVersion(ctx context.Context, lockId string, ...) error
- type MongoStorageOptions
- func (x *MongoStorageOptions) Check() error
- func (x *MongoStorageOptions) SetCollectionName(collectionName string) *MongoStorageOptions
- func (x *MongoStorageOptions) SetConnectionManager(connectionProvider storage.ConnectionManager[*mongo.Client]) *MongoStorageOptions
- func (x *MongoStorageOptions) SetDatabaseName(databaseName string) *MongoStorageOptions
Constants ¶
View Source
const MongoConnectionManagerName = "mongodb-connection-manager"
View Source
const MongoStorageName = "mongodb-storage"
Variables ¶
View Source
var ( // ErrDatabaseNameEmpty 参数中数据库名字为空 ErrDatabaseNameEmpty = fmt.Errorf("DatabaseName can not empty") // ErrCollectionNameEmpty 参数中集合名字为空 ErrCollectionNameEmpty = fmt.Errorf("CollectionName can not empty") // ErrConnectionManagerNil 连接管理器没有指定 ErrConnectionManagerNil = fmt.Errorf("ConnectionManager can not nil") )
Functions ¶
This section is empty.
Types ¶
type ListMongoLockIterator ¶
type ListMongoLockIterator struct {
// contains filtered or unexported fields
}
ListMongoLockIterator 用于迭代列出mongo中的所有的锁
func NewListMongoLockIterator ¶
func NewListMongoLockIterator(cursor *mongo.Cursor) *ListMongoLockIterator
func (*ListMongoLockIterator) Next ¶
func (x *ListMongoLockIterator) Next() bool
func (*ListMongoLockIterator) Value ¶
func (x *ListMongoLockIterator) Value() *storage.LockInformation
type MongoConnectionManager ¶
type MongoConnectionManager struct { // 连接到数据库的地址 URI string // contains filtered or unexported fields }
MongoConnectionManager 负责维护与Mongo数据库的连接
func NewMongoConnectionManagerFromClient ¶
func NewMongoConnectionManagerFromClient(client *mongo.Client) *MongoConnectionManager
NewMongoConnectionManagerFromClient 复用已经存在的mongo client,从其创建连接管理器
func NewMongoConnectionManagerFromURI ¶
func NewMongoConnectionManagerFromURI(uri string) *MongoConnectionManager
NewMongoConnectionManagerFromURI 从Mongo uri创建连接管理器
func (*MongoConnectionManager) Name ¶
func (x *MongoConnectionManager) Name() string
type MongoLock ¶
type MongoLock struct { // 锁的ID,这个字段是一个唯一字段,这个字段会作为Mongo中的Collection的主键字段,保证同一个锁同时只会存在一个 ID string `bson:"_id"` // 锁的当前持有者的ID OwnerId string `bson:"owner_id"` // 锁的版本,每次修改都会增加1 Version storage.Version `bson:"version"` // 锁的json信息,存储着更上层的通用的锁的信息,这里只需要认为它是一个字符串就可以了 LockJsonString string `bson:"lock_json_string"` }
MongoLock 锁在Mongo中存储的结构
type MongoStorage ¶
type MongoStorage struct {
// contains filtered or unexported fields
}
MongoStorage MongoDB的存储引擎实现
func NewMongoStorage ¶
func NewMongoStorage(ctx context.Context, options *MongoStorageOptions) (*MongoStorage, error)
NewMongoStorage 创建一个基于MongoDB的存储引擎
func (*MongoStorage) CreateWithVersion ¶
func (x *MongoStorage) CreateWithVersion(ctx context.Context, lockId string, version storage.Version, lockInformation *storage.LockInformation) error
func (*MongoStorage) DeleteWithVersion ¶
func (x *MongoStorage) DeleteWithVersion(ctx context.Context, lockId string, exceptedVersion storage.Version, lockInformation *storage.LockInformation) error
func (*MongoStorage) GetName ¶
func (x *MongoStorage) GetName() string
func (*MongoStorage) List ¶
func (x *MongoStorage) List(ctx context.Context) (iterator.Iterator[*storage.LockInformation], error)
func (*MongoStorage) UpdateWithVersion ¶
func (x *MongoStorage) UpdateWithVersion(ctx context.Context, lockId string, exceptedVersion, newVersion storage.Version, lockInformation *storage.LockInformation) error
type MongoStorageOptions ¶
type MongoStorageOptions struct { // 获取连接 ConnectionManager storage.ConnectionManager[*mongo.Client] // 要存储到的数据库的名称 DatabaseName string // 集合名称 CollectionName string }
MongoStorageOptions Mongo的存储选项
func NewMongoStorageOptions ¶
func NewMongoStorageOptions() *MongoStorageOptions
func NewMongoStorageOptionsWithURI ¶
func NewMongoStorageOptionsWithURI(uri string) *MongoStorageOptions
func (*MongoStorageOptions) Check ¶
func (x *MongoStorageOptions) Check() error
func (*MongoStorageOptions) SetCollectionName ¶
func (x *MongoStorageOptions) SetCollectionName(collectionName string) *MongoStorageOptions
func (*MongoStorageOptions) SetConnectionManager ¶
func (x *MongoStorageOptions) SetConnectionManager(connectionProvider storage.ConnectionManager[*mongo.Client]) *MongoStorageOptions
func (*MongoStorageOptions) SetDatabaseName ¶
func (x *MongoStorageOptions) SetDatabaseName(databaseName string) *MongoStorageOptions
Source Files ¶
Click to show internal directories.
Click to hide internal directories.