adapter

package
v0.1.100 Latest Latest
Warning

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

Go to latest
Published: May 14, 2020 License: Apache-2.0 Imports: 22 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultMongoId = "mongo"
	ErrInvalidOpt  = "mongo: invalid option "
)

mongo

View Source
const (
	DefaultDbTimeout = 10 * time.Second
	DefaultDbId      = "db"
)

db

View Source
const (
	DefaultHttpId = "http"
)

http

View Source
const (
	DefaultMaxMindId = "maxMind"
)

maxMind

View Source
const (
	DefaultMemCacheId = "memCache"
)

memCache

View Source
const (
	DefaultMemoryId = "memory"
)

memory

View Source
const (
	DefaultRabbitId = "rabbitMq"
)

rabbitMq

View Source
const (
	DefaultRedisId = "redis"
)

redis

Variables

View Source
var DbClass string
View Source
var HttpClass string
View Source
var MaxMindClass string
View Source
var MemCacheClass string
View Source
var MemoryClass string
View Source
var MongoClass string
View Source
var RabbitMqClass string
View Source
var RedisClass string

Functions

func NewDbPool

func NewDbPool(iObj iface.IObject, componentId ...interface{}) iface.IObject

NewDbPool of db Client from pool, add context support. usage: db := this.GetObjPool(adapter.DbClass, adapter.NewDbPool).(adapter.IDb)/(*adapter.Db)

func NewHttpPool

func NewHttpPool(iObj iface.IObject, componentId ...interface{}) iface.IObject

Http of Http Client from pool, add context support. usage: http := this.GetObjPool(adapter.HttpClass, adapter.NewHttpPool).(adapter.IHttp)/(*adapter.Http)

func NewMaxMindPool

func NewMaxMindPool(iObj iface.IObject, componentId ...interface{}) iface.IObject

NewMaxMindPool of MaxMind Client from pool, add context support. usage: mmd := this.GetObjPool(adapter.MaxMindClass, adapter.NewMaxMindPool).(adapter.IMaxMind)/(*adapter.MaxMind)

func NewMemCachePool

func NewMemCachePool(iObj iface.IObject, componentId ...interface{}) iface.IObject

NewMemCachePool of MemCache Client from pool, add context support. usage: mc := this.GetObjPool(adapter.MemCacheClass, adapter.NewMemCachePool).(adapter.IMemCache)/(*adapter.MemCache)

func NewMemoryPool

func NewMemoryPool(iObj iface.IObject, componentId ...interface{}) iface.IObject

NewMemoryPool of Memory Client from object pool, add context support. usage: memory := this.GetObjPool(adapter.MemoryClass, adapter.NewMemoryPool).(adapter.IMemory)/(*adapter.Memory)

func NewMongoPool

func NewMongoPool(iObj iface.IObject, args ...interface{}) iface.IObject

NewMongoPool of Mongo Client from pool, add context support. usage: mongo := this.GetObjectPool(adapter.MongoClass, adapter.NewMongoPool,db, coll)).(adapter.IMongo)/(*adapter.Mongo)

func NewRabbitMqPool

func NewRabbitMqPool(iObj iface.IObject, componentId ...interface{}) iface.IObject

NewRabbitMqPool of RabbitMq Client from pool, add context support. usage: rabbitMq := this.GetObjPool(adapter.RabbitMqClass,adapter.NewRabbitMqPool).(adapter.IRabbitMq)/(*adapter.RabbitMq)

func NewRedisPool

func NewRedisPool(iObj iface.IObject, componentId ...interface{}) iface.IObject

NewRedisPool of Redis Client from pool, add context support. usage: redis := this.GetObjPool(adapter.RedisClass, adapter.NewRedisPool).(*adapter.Redis)

Types

type Db

type Db struct {
	// contains filtered or unexported fields
}

func NewDb

func NewDb(componentId ...string) *Db

NewDb of db Client, add context support. usage: db := this.GetObj(adapter.NewDb()).(adapter.IDb)/(*adapter.Db)

func (*Db) Begin

func (d *Db) Begin(opts ...*sql.TxOptions) ITx

Begin start a transaction with default timeout context and optional opts, if opts is nil, default driver option will be used.

func (*Db) BeginContext

func (d *Db) BeginContext(ctx context.Context, opts *sql.TxOptions) ITx

BeginContext start a transaction with specified context and optional opts, if opts is nil, default driver option will be used.

func (*Db) Exec

func (d *Db) Exec(query string, args ...interface{}) sql.Result

Exec perform exec using a default timeout context.

func (*Db) ExecContext

func (d *Db) ExecContext(ctx context.Context, query string, args ...interface{}) sql.Result

ExecContext perform exec using a specified context.

func (*Db) GetClient

func (d *Db) GetClient() *db.Client

func (*Db) GetDb

func (d *Db) GetDb(master bool) *sql.DB

func (*Db) Master

func (d *Db) Master() bool

func (*Db) Prepare

func (d *Db) Prepare(query string) IStmt

Prepare creates a prepared statement for later queries or executions, the Close method must be called by caller.

func (*Db) PrepareContext

func (d *Db) PrepareContext(ctx context.Context, query string) IStmt

PrepareContext creates a prepared statement for later queries or executions, the Close method must be called by caller.

func (*Db) Query

func (d *Db) Query(query string, args ...interface{}) *sql.Rows

Query perform query using a default timeout context.

func (*Db) QueryContext

func (d *Db) QueryContext(ctx context.Context, query string, args ...interface{}) *sql.Rows

QueryContext perform query using a specified context.

func (*Db) QueryOne

func (d *Db) QueryOne(query string, args ...interface{}) IRow

QueryOne perform one row query using a default timeout context, and always returns a non-nil value, Errors are deferred until Row's Scan method is called.

func (*Db) QueryOneContext

func (d *Db) QueryOneContext(ctx context.Context, query string, args ...interface{}) IRow

QueryOneContext perform one row query using a specified context, and always returns a non-nil value, Errors are deferred until Row's Scan method is called.

func (*Db) SetMaster

func (d *Db) SetMaster(v bool)

type Http

type Http struct {
	pgo2.Object
	// contains filtered or unexported fields
}

func NewHttp

func NewHttp(componentId ...string) *Http

Http of Http Client, add context support. usage: http := this.GetObj(adapter.NewHttp()).(adapter.IHttp)/(*adapter.Http)

func (*Http) Do

func (h *Http) Do(req *http.Request, option ...*phttp.Option) *http.Response

Do perform a single request

func (*Http) DoMulti

func (h *Http) DoMulti(requests []*http.Request, option ...*phttp.Option) []*http.Response

DoMulti perform multi requests concurrently

func (*Http) Get

func (h *Http) Get(addr string, data interface{}, option ...*phttp.Option) *http.Response

Get perform a get request

func (*Http) GetClient

func (h *Http) GetClient() *phttp.Client

func (*Http) Post

func (h *Http) Post(addr string, data interface{}, option ...*phttp.Option) *http.Response

Post perform a post request

func (*Http) SetPanicRecover

func (h *Http) SetPanicRecover(v bool)

type IDb

type IDb interface {
	SetMaster(v bool)
	GetDb(master bool) *sql.DB
	Begin(opts ...*sql.TxOptions) ITx
	BeginContext(ctx context.Context, opts *sql.TxOptions) ITx
	QueryOne(query string, args ...interface{}) IRow
	QueryOneContext(ctx context.Context, query string, args ...interface{}) IRow
	Query(query string, args ...interface{}) *sql.Rows
	QueryContext(ctx context.Context, query string, args ...interface{}) *sql.Rows
	Exec(query string, args ...interface{}) sql.Result
	ExecContext(ctx context.Context, query string, args ...interface{}) sql.Result
	Prepare(query string) IStmt
	PrepareContext(ctx context.Context, query string) IStmt
}

type IHttp

type IHttp interface {
	SetPanicRecover(v bool)
	Get(addr string, data interface{}, option ...*phttp.Option) *http.Response
	Post(addr string, data interface{}, option ...*phttp.Option) *http.Response
	Do(req *http.Request, option ...*phttp.Option) *http.Response
	DoMulti(requests []*http.Request, option ...*phttp.Option) []*http.Response
}

type IMaxMind

type IMaxMind interface {
	GeoByIp(ip string, args ...interface{}) *maxmind.Geo
}

type IMemCache

type IMemCache interface {
	SetPanicRecover(v bool)
	Get(key string) *value.Value
	MGet(keys []string) map[string]*value.Value
	Set(key string, value interface{}, expire ...time.Duration) bool
	MSet(items map[string]interface{}, expire ...time.Duration) bool
	Add(key string, value interface{}, expire ...time.Duration) bool
	MAdd(items map[string]interface{}, expire ...time.Duration) bool
	Del(key string) bool
	MDel(keys []string) bool
	Exists(key string) bool
	Incr(key string, delta int) int
	Retrieve(cmd, key string) *memcache.Item
	MultiRetrieve(cmd string, keys []string) []*memcache.Item
	Store(cmd string, item *memcache.Item, expire ...time.Duration) bool
	MultiStore(cmd string, items []*memcache.Item, expire ...time.Duration) bool
}

type IMemory

type IMemory interface {
	SetPanicRecover(v bool)
	Get(key string) *value.Value
	MGet(keys []string) map[string]*value.Value
	Set(key string, value interface{}, expire ...time.Duration) bool
	MSet(items map[string]interface{}, expire ...time.Duration) bool
	Add(key string, value interface{}, expire ...time.Duration) bool
	MAdd(items map[string]interface{}, expire ...time.Duration) bool
	Del(key string) bool
	MDel(keys []string) bool
	Exists(key string) bool
	Incr(key string, delta int) int
}

type IMongo

type IMongo interface {
	FindOne(query interface{}, result interface{}, options ...bson.M) error
	FindAll(query interface{}, result interface{}, options ...bson.M) error
	FindAndModify(query interface{}, change mgo.Change, result interface{}, options ...bson.M) error
	FindDistinct(query interface{}, key string, result interface{}, options ...bson.M) error
	InsertOne(doc interface{}) error
	InsertAll(docs []interface{}) error
	UpdateOne(query interface{}, update interface{}) error
	UpdateAll(query interface{}, update interface{}) error
	UpdateOrInsert(query interface{}, update interface{}) error
	DeleteOne(query interface{}) error
	DeleteAll(query interface{}) error
	Count(query interface{}, options ...bson.M) (int, error)
	PipeOne(pipeline interface{}, result interface{}) error
	PipeAll(pipeline interface{}, result interface{}) error
	MapReduce(query interface{}, job *mgo.MapReduce, result interface{}, options ...bson.M) error
}

type IRabbitMq

type IRabbitMq interface {
	SetPanicRecover(v bool)
	ExchangeDeclare(dftExchange ...*rabbitmq.ExchangeData)
	Publish(opCode string, data interface{}, dftOpUid ...string) bool
	PublishExchange(serviceName, exchangeName, exchangeType, opCode string, data interface{}, dftOpUid ...string) bool
	GetConsumeChannelBox(queueName string, opCodes []string, dftExchange ...*rabbitmq.ExchangeData) *rabbitmq.ChannelBox
	Consume(queueName string, opCodes []string, limit int, autoAck, noWait, exclusive bool) <-chan amqp.Delivery
	ConsumeExchange(exchangeName, exchangeType, queueName string, opCodes []string, limit int, autoAck, noWait, exclusive bool) <-chan amqp.Delivery
	DecodeBody(d amqp.Delivery, ret interface{}) error
	DecodeHeaders(d amqp.Delivery) *rabbitmq.RabbitHeaders
}

type IRedis

type IRedis interface {
	SetPanicRecover(v bool)
	Get(key string) *value.Value
	MGet(keys []string) map[string]*value.Value
	Set(key string, value interface{}, expire ...time.Duration) bool
	MSet(items map[string]interface{}, expire ...time.Duration) bool
	Add(key string, value interface{}, expire ...time.Duration) bool
	MAdd(items map[string]interface{}, expire ...time.Duration) bool
	Del(key string) bool
	MDel(keys []string) bool
	Exists(key string) bool
	Incr(key string, delta int) int
	Do(cmd string, args ...interface{}) interface{}
}

type IRow

type IRow interface {
	iface.IObject
	Scan(dest ...interface{}) error
}

type IStmt

type IStmt interface {
	iface.IObject
	Close()
	QueryOne(args ...interface{}) IRow
	QueryOneContext(ctx context.Context, args ...interface{}) IRow
	Query(args ...interface{}) *sql.Rows
	QueryContext(ctx context.Context, args ...interface{}) *sql.Rows
	Exec(args ...interface{}) sql.Result
	ExecContext(ctx context.Context, args ...interface{}) sql.Result
}

type ITx

type ITx interface {
	iface.IObject
	Commit() bool
	Rollback() bool
	QueryOne(query string, args ...interface{}) IRow
	QueryOneContext(ctx context.Context, query string, args ...interface{}) IRow
	Query(query string, args ...interface{}) *sql.Rows
	QueryContext(ctx context.Context, query string, args ...interface{}) *sql.Rows
	Exec(query string, args ...interface{}) sql.Result
	ExecContext(ctx context.Context, query string, args ...interface{}) sql.Result
	Prepare(query string) IStmt
	PrepareContext(ctx context.Context, query string) IStmt
}

type MaxMind

type MaxMind struct {
	pgo2.Object
	// contains filtered or unexported fields
}

func NewMaxMind

func NewMaxMind(componentId ...string) *MaxMind

NewMaxMind of MaxMind Client, add context support. usage: mmd := this.GetObj(adapter.NewMaxMind()).(adapter.IMaxMind)/(*adapter.MaxMind)

func (*MaxMind) GeoByIp

func (m *MaxMind) GeoByIp(ip string, args ...interface{}) *maxmind.Geo

get geo info by ip, optional args: db int: preferred max mind db lang string: preferred i18n language

func (*MaxMind) GetClient

func (m *MaxMind) GetClient() *maxmind.Client

type MemCache

type MemCache struct {
	pgo2.Object
	// contains filtered or unexported fields
}

func NewMemCache

func NewMemCache(componentId ...string) *MemCache

NewMemCache of MemCache Client, add context support. usage: mc := this.GetObj(adapter.NewMemCache()).(adapter.IMemCache)/(*adapter.MemCache)

func (*MemCache) Add

func (m *MemCache) Add(key string, value interface{}, expire ...time.Duration) bool

func (*MemCache) Del

func (m *MemCache) Del(key string) bool

func (*MemCache) Exists

func (m *MemCache) Exists(key string) bool

func (*MemCache) Get

func (m *MemCache) Get(key string) *value.Value

func (*MemCache) GetClient

func (m *MemCache) GetClient() *memcache.Client

func (*MemCache) Incr

func (m *MemCache) Incr(key string, delta int) int

func (*MemCache) MAdd

func (m *MemCache) MAdd(items map[string]interface{}, expire ...time.Duration) bool

func (*MemCache) MDel

func (m *MemCache) MDel(keys []string) bool

func (*MemCache) MGet

func (m *MemCache) MGet(keys []string) map[string]*value.Value

func (*MemCache) MSet

func (m *MemCache) MSet(items map[string]interface{}, expire ...time.Duration) bool

func (*MemCache) MultiRetrieve

func (m *MemCache) MultiRetrieve(cmd string, keys []string) []*memcache.Item

func (*MemCache) MultiStore

func (m *MemCache) MultiStore(cmd string, items []*memcache.Item, expire ...time.Duration) bool

func (*MemCache) Retrieve

func (m *MemCache) Retrieve(cmd, key string) *memcache.Item

func (*MemCache) Set

func (m *MemCache) Set(key string, value interface{}, expire ...time.Duration) bool

func (*MemCache) SetPanicRecover

func (m *MemCache) SetPanicRecover(v bool)

func (*MemCache) Store

func (m *MemCache) Store(cmd string, item *memcache.Item, expire ...time.Duration) bool

type Memory

type Memory struct {
	pgo2.Object
	// contains filtered or unexported fields
}

func NewMemory

func NewMemory(componentId ...string) *Memory

NewMemory of Memory Client, add context support. usage: memory := this.GetObj(adapter.NewMemory()).(adapter.IMemory)/(*adapter.Memory)

func (*Memory) Add

func (m *Memory) Add(key string, value interface{}, expire ...time.Duration) bool

func (*Memory) Client

func (m *Memory) Client() *memory.Client

func (*Memory) Del

func (m *Memory) Del(key string) bool

func (*Memory) Exists

func (m *Memory) Exists(key string) bool

func (*Memory) Get

func (m *Memory) Get(key string) *value.Value

func (*Memory) Incr

func (m *Memory) Incr(key string, delta int) int

func (*Memory) MAdd

func (m *Memory) MAdd(items map[string]interface{}, expire ...time.Duration) bool

func (*Memory) MDel

func (m *Memory) MDel(keys []string) bool

func (*Memory) MGet

func (m *Memory) MGet(keys []string) map[string]*value.Value

func (*Memory) MSet

func (m *Memory) MSet(items map[string]interface{}, expire ...time.Duration) bool

func (*Memory) Set

func (m *Memory) Set(key string, value interface{}, expire ...time.Duration) bool

func (*Memory) SetPanicRecover

func (m *Memory) SetPanicRecover(v bool)

type Mongo

type Mongo struct {
	pgo2.Object
	// contains filtered or unexported fields
}

func NewMongo

func NewMongo(db, coll string, componentId ...string) *Mongo

NewMongo of Mongo Client, add context support. usage: mongo := this.GetObject(adapter.NewMongo(db, coll)).(adapter.IMongo)/(*adapter.Mongo)

func (*Mongo) Count

func (m *Mongo) Count(query interface{}, options ...bson.M) (int, error)

Count return the count of documents match the query.

func (*Mongo) DeleteAll

func (m *Mongo) DeleteAll(query interface{}) error

DeleteAll delete all documents that match the query.

func (*Mongo) DeleteOne

func (m *Mongo) DeleteOne(query interface{}) error

DeleteOne delete one document that match the query.

func (*Mongo) FindAll

func (m *Mongo) FindAll(query interface{}, result interface{}, options ...bson.M) error

FindAll retrieve all documents that match the query, param result must be a slice(interface{}, map, bson.M or bson compatible struct) other params see FindOne()

func (*Mongo) FindAndModify

func (m *Mongo) FindAndModify(query interface{}, change mgo.Change, result interface{}, options ...bson.M) error

FindAndModify execute findAndModify command, which allows atomically update or remove one document, param change specify the change operation, eg. mgo.Change{Update:bson.M{"$inc": bson.M{"n":1}}, ReturnNew:true}, other params see FindOne()

func (*Mongo) FindDistinct

func (m *Mongo) FindDistinct(query interface{}, key string, result interface{}, options ...bson.M) error

FindDistinct retrieve distinct values for the param key, param result must be a slice, other params see FindOne()

func (*Mongo) FindOne

func (m *Mongo) FindOne(query interface{}, result interface{}, options ...bson.M) error

FindOne retrieve the first document that match the query, query can be a map or bson compatible struct, such as bson.M or properly typed map, nil query is equivalent to empty query such as bson.M{}. result is pointer to interface{}, map, bson.M or bson compatible struct, if interface{} type is provided, the output result is a bson.M. options provided optional query option listed as follows: fields: bson.M, set output fields, eg. bson.M{"_id":0, "name":1}, sort: string or []string, set sort order, eg. "key1" or []string{"key1", "-key2"}, skip: int, set skip number, eg. 100, limit: int, set result limit, eg. 1, hint: string or []string, set index hint, eg. []string{"key1", "key2"}

for example:

var v1 interface{} // type of output v1 is bson.M
m.FindOne(bson.M{"_id":"k1"}, &v1)

var v2 struct {
    Id    string `bson:"_id"`
    Name  string `bson:"name"`
    Value string `bson:"value"`
}
m.FindOne(bson.M{"_id": "k1"}, &v2)

func (*Mongo) GetClient

func (m *Mongo) GetClient() *mongo.Client

func (*Mongo) InsertAll

func (m *Mongo) InsertAll(docs []interface{}) error

InsertAll insert all documents provided by params docs into collection, for example:

docs := []interface{}{
    bson.M{"_id":1, "name":"v1"},
    bson.M{"_id":2, "name":"v2"},
}
m.InsertAll(docs)

func (*Mongo) InsertOne

func (m *Mongo) InsertOne(doc interface{}) error

InsertOne insert one document into collection, param doc can be a map, bson.M, bson compatible struct, for example:

m.InsertOne(bson.M{"field1":"value1", "field2":"value2"})

doc := struct {
    Field1 string `bson:"field1"`
    Field2 string `bson:"field2"`
} {"value1", "value2"}
m.InsertOne(doc)

func (*Mongo) MapReduce

func (m *Mongo) MapReduce(query interface{}, job *mgo.MapReduce, result interface{}, options ...bson.M) error

MapReduce execute map/reduce job that match the query. param result is a slice(interface{}, map, bson.M, bson compatible struct), param query and options see FindOne(). for example:

job := &mgo.MapReduce{
    Map: "function() { emit(this.n, 1) }",
    Reduce: "function(key, values) { return Array.sum(values) }",
}
result := []bson.M{}
m.MapReduce(query, job, &result)

func (*Mongo) PipeAll

func (m *Mongo) PipeAll(pipeline interface{}, result interface{}) error

PipeAll execute aggregation queries and get all item from result set. param result must be slice(interface{}, map, bson.M or bson compatible struct). see PipeOne().

func (*Mongo) PipeOne

func (m *Mongo) PipeOne(pipeline interface{}, result interface{}) error

PipeOne execute aggregation queries and get the first item from result set. param pipeline must be a slice, such as []bson.M, param result is a pointer to interface{}, map, bson.M or bson compatible struct. for example:

pipeline := []bson.M{
    bson.M{"$match": bson.M{"status":"A"}},
    bson.M{"$group": bson.M{"_id":"$field1", "total":"$field2"}},
}
m.PipeOne(pipeline, &result)

func (*Mongo) UpdateAll

func (m *Mongo) UpdateAll(query interface{}, update interface{}) error

UpdateAll update all documents that match the query, see UpdateOne()

func (*Mongo) UpdateOne

func (m *Mongo) UpdateOne(query interface{}, update interface{}) error

UpdateOne update one document that match the query, mgo.ErrNotFound is returned if a document not found, a value of *LastError is returned if other error occurred.

func (*Mongo) UpdateOrInsert

func (m *Mongo) UpdateOrInsert(query interface{}, update interface{}) error

UpdateOrInsert update a existing document that match the query, or insert a new document base on the update document if no document match, an error of *LastError is returned if error is detected.

type RabbitMq

type RabbitMq struct {
	pgo2.Object
	// contains filtered or unexported fields
}

func NewRabbitMq

func NewRabbitMq(componentId ...string) *RabbitMq

NewRabbitMq of RabbitMq Client, add context support. usage: rabbitMq := this.GetObj(adapter.NewRabbitMq()).(adapter.IRabbitMq)/(*adapter.RabbitMq)

func (*RabbitMq) Consume

func (r *RabbitMq) Consume(queueName string, opCodes []string, limit int, autoAck, noWait, exclusive bool) <-chan amqp.Delivery

消费,返回chan 可以不停取数据 queueName 队列名字 opCodes 绑定队列的code limit 每次接收多少条 autoAck 是否自动答复 如果为false 需要手动调用Delivery.ack(false) noWait 是否一直等待 exclusive 是否独占队列

func (*RabbitMq) ConsumeExchange added in v0.1.99

func (r *RabbitMq) ConsumeExchange(exchangeName, exchangeType, queueName string, opCodes []string, limit int, autoAck, noWait, exclusive bool) <-chan amqp.Delivery

消费,返回chan 可以不停取数据 exchangeName 交换机名 exchangeType 交换机type queueName 队列名字 opCodes 绑定队列的code limit 每次接收多少条 autoAck 是否自动答复 如果为false 需要手动调用Delivery.ack(false) noWait 是否一直等待 exclusive 是否独占队列

func (*RabbitMq) DecodeBody

func (r *RabbitMq) DecodeBody(d amqp.Delivery, ret interface{}) error

func (*RabbitMq) DecodeHeaders

func (r *RabbitMq) DecodeHeaders(d amqp.Delivery) *rabbitmq.RabbitHeaders

func (*RabbitMq) ExchangeDeclare

func (r *RabbitMq) ExchangeDeclare(dftExchange ...*rabbitmq.ExchangeData)

func (*RabbitMq) GetClient

func (r *RabbitMq) GetClient() *rabbitmq.Client

func (*RabbitMq) GetConsumeChannelBox

func (r *RabbitMq) GetConsumeChannelBox(queueName string, opCodes []string, dftExchange ...*rabbitmq.ExchangeData) *rabbitmq.ChannelBox

func (*RabbitMq) Publish

func (r *RabbitMq) Publish(opCode string, data interface{}, dftOpUid ...string) bool

func (*RabbitMq) PublishExchange added in v0.1.99

func (r *RabbitMq) PublishExchange(serviceName, exchangeName, exchangeType, opCode string, data interface{}, dftOpUid ...string) bool

func (*RabbitMq) SetPanicRecover

func (r *RabbitMq) SetPanicRecover(v bool)

type Redis

type Redis struct {
	pgo2.Object
	// contains filtered or unexported fields
}

func NewRedis

func NewRedis(componentId ...string) *Redis

NewRedis of Redis Client, add context support. usage: redis := this.GetObject(adapter.NewRedis()).(*adapter.Redis)

func (*Redis) Add

func (r *Redis) Add(key string, value interface{}, expire ...time.Duration) bool

func (*Redis) Del

func (r *Redis) Del(key string) bool

func (*Redis) Do

func (r *Redis) Do(cmd string, args ...interface{}) interface{}

支持的命令请查阅:Redis.allRedisCmd args = [0:"key"] Example: redis := t.GetObject(Redis.AdapterClass).(*Redis.Adapter) retI := redis.Do("SADD","myTest", "test1" ret := retI.(int) fmt.Println(ret) = 1 retList :=redis.Do("SMEMBERS","myTest" retListI,_:=ret.([]interface{})

for _,v:=range retListI{
   vv :=pgo.NewValue(v) // 写入的时候有pgo.Encode(),如果存入的是结构体或slice map 需要decode,其他类型直接断言类型
   fmt.Println(vv.String()) // test1
}

func (*Redis) Exists

func (r *Redis) Exists(key string) bool

func (*Redis) Get

func (r *Redis) Get(key string) *value.Value

func (*Redis) GetClient

func (r *Redis) GetClient() *redis.Client

func (*Redis) Incr

func (r *Redis) Incr(key string, delta int) int

func (*Redis) MAdd

func (r *Redis) MAdd(items map[string]interface{}, expire ...time.Duration) bool

func (*Redis) MDel

func (r *Redis) MDel(keys []string) bool

func (*Redis) MGet

func (r *Redis) MGet(keys []string) map[string]*value.Value

func (*Redis) MSet

func (r *Redis) MSet(items map[string]interface{}, expire ...time.Duration) bool

func (*Redis) Set

func (r *Redis) Set(key string, value interface{}, expire ...time.Duration) bool

func (*Redis) SetPanicRecover

func (r *Redis) SetPanicRecover(v bool)

type Row

type Row struct {
	// contains filtered or unexported fields
}

Row wrapper for sql.Row

func (*Row) Scan

func (r *Row) Scan(dest ...interface{}) error

Scan copies the columns in the current row into the values pointed at by dest.

type Stmt

type Stmt struct {
	// contains filtered or unexported fields
}

Stmt wrap sql.Stmt, add context support

func (*Stmt) Close

func (s *Stmt) Close()

Close close sql.Stmt and return instance to pool

func (*Stmt) Exec

func (s *Stmt) Exec(args ...interface{}) sql.Result

Exec perform exec using a default timeout context.

func (*Stmt) ExecContext

func (s *Stmt) ExecContext(ctx context.Context, args ...interface{}) sql.Result

ExecContext perform exec using a specified context.

func (*Stmt) Query

func (s *Stmt) Query(args ...interface{}) *sql.Rows

Query perform query using a default timeout context.

func (*Stmt) QueryContext

func (s *Stmt) QueryContext(ctx context.Context, args ...interface{}) *sql.Rows

QueryContext perform query using a specified context.

func (*Stmt) QueryOne

func (s *Stmt) QueryOne(args ...interface{}) IRow

QueryOne perform one row query using a default timeout context, and always returns a non-nil value, Errors are deferred until Row's Scan method is called.

func (*Stmt) QueryOneContext

func (s *Stmt) QueryOneContext(ctx context.Context, args ...interface{}) IRow

QueryOneContext perform one row query using a specified context, and always returns a non-nil value, Errors are deferred until Row's Scan method is called.

type Tx

type Tx struct {
	// contains filtered or unexported fields
}

Tx wrapper for sql.Tx

func (*Tx) Commit

func (t *Tx) Commit() bool

Commit commit transaction that previously started.

func (*Tx) Exec

func (t *Tx) Exec(query string, args ...interface{}) sql.Result

Exec perform exec using a default timeout context.

func (*Tx) ExecContext

func (t *Tx) ExecContext(ctx context.Context, query string, args ...interface{}) sql.Result

ExecContext perform exec using a specified context.

func (*Tx) Prepare

func (t *Tx) Prepare(query string) IStmt

Prepare creates a prepared statement for later queries or executions, the Close method must be called by caller.

func (*Tx) PrepareContext

func (t *Tx) PrepareContext(ctx context.Context, query string) IStmt

PrepareContext creates a prepared statement for later queries or executions, the Close method must be called by caller.

func (*Tx) Query

func (t *Tx) Query(query string, args ...interface{}) *sql.Rows

Query perform query using a default timeout context.

func (*Tx) QueryContext

func (t *Tx) QueryContext(ctx context.Context, query string, args ...interface{}) *sql.Rows

QueryContext perform query using a specified context.

func (*Tx) QueryOne

func (t *Tx) QueryOne(query string, args ...interface{}) IRow

QueryOne perform one row query using a default timeout context, and always returns a non-nil value, Errors are deferred until Row's Scan method is called.

func (*Tx) QueryOneContext

func (t *Tx) QueryOneContext(ctx context.Context, query string, args ...interface{}) IRow

QueryOneContext perform one row query using a specified context, and always returns a non-nil value, Errors are deferred until Row's Scan method is called.

func (*Tx) Rollback

func (t *Tx) Rollback() bool

Rollback roll back transaction that previously started.

Jump to

Keyboard shortcuts

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