infra

package
v1.0.1-0...-7ff242b Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 15, 2021 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNotConnected = errors.New("redis: client not connected")
	ErrNotFound     = errors.New("mongo: not found")
)

list of infra errors.

Functions

This section is empty.

Types

type Index

type Index struct {
	Keys   []IndexKey
	Name   string
	Unique bool
	Sparse bool
}

Index represents a mongodb index

type IndexKey

type IndexKey struct {
	Key  string
	Desc bool
}

IndexKey holds a key of index

type MongoClient

type MongoClient struct {
	URL    string
	ExpDur int32
	// contains filtered or unexported fields
}

MongoClient contains required field

func NewMongoClient

func NewMongoClient(url string, ttl time.Duration) (*MongoClient, error)

NewMongoClient return a mongo client

func (*MongoClient) AbortTransaction

func (m *MongoClient) AbortTransaction(ctx context.Context) (interface{}, error)

AbortTransaction aborts a transaction

func (*MongoClient) Aggregate

func (m *MongoClient) Aggregate(ctx context.Context, q interface{}) (*mongo.Cursor, error)

Aggregate handles aggregation and return a Cursor

func (*MongoClient) Close

func (m *MongoClient) Close() error

Close close the mongo connection

func (*MongoClient) CommitTransaction

func (m *MongoClient) CommitTransaction(ctx context.Context) (interface{}, error)

CommitTransaction finishes the transaction

func (*MongoClient) Connect

func (m *MongoClient) Connect() error

Connect initiate a mongo connection

func (*MongoClient) Create

func (m *MongoClient) Create(ctx context.Context, t interface{}) error

Create create a object

func (*MongoClient) DropIndices

func (m *MongoClient) DropIndices() error

DropIndices drop previous mongo field

func (*MongoClient) EnsureIndices

func (m *MongoClient) EnsureIndices(indices []Index) error

EnsureIndices ensure mongo index list

func (*MongoClient) Get

func (m *MongoClient) Get(ctx context.Context, q bson.M) (*mongo.SingleResult, error)

Get return a single object based on query parameter

func (*MongoClient) List

func (m *MongoClient) List(ctx context.Context, q interface{}, skip, limit int) (*mongo.Cursor, error)

List return a list of object based on query parameter

func (*MongoClient) Ping

func (m *MongoClient) Ping() error

Ping check the mongo connection status

func (*MongoClient) SetTTL

func (m *MongoClient) SetTTL() (interface{}, error)

SetTTL for mongo object

func (*MongoClient) StartTransaction

func (m *MongoClient) StartTransaction(ctx context.Context, id string) (context.Context, error)

StartTransaction starts the transaction

func (*MongoClient) Update

func (m *MongoClient) Update(ctx context.Context, q, val interface{}) error

Update update a object

func (*MongoClient) UpdatePartial

func (m *MongoClient) UpdatePartial(ctx context.Context, q, val interface{}) error

UpdatePartial update a object partially

type RedisClient

type RedisClient struct {
	URL string

	ExpDur int64
	// contains filtered or unexported fields
}

RedisClient contain necessary field

func NewRedisClient

func NewRedisClient(url string, ttl time.Duration) *RedisClient

NewRedisClient return a new RedisClient instance

func (*RedisClient) Close

func (s *RedisClient) Close() error

Close close the redis connection

func (*RedisClient) Create

func (s *RedisClient) Create(key string, t []byte) error

Create create a new object

func (*RedisClient) Get

func (s *RedisClient) Get(key string) ([]byte, error)

Get return a byte string based on key

func (*RedisClient) Ping

func (s *RedisClient) Ping() error

Ping check the redis connection

func (*RedisClient) Update

func (s *RedisClient) Update(key string, t []byte) error

Update will update the object

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL