types

package
v1.0.63 Latest Latest
Warning

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

Go to latest
Published: Aug 28, 2023 License: MPL-2.0 Imports: 9 Imported by: 11

Documentation

Index

Constants

View Source
const (
	SdkTypeMqRabbitmq // rabbitmq消息队列能力
	SdkTypeMqKafka    // kafka
)

message queue provider

View Source
const (
	ProviderTypeDefault = "default"
	ProviderTypeMaster  = "master"
	ProviderTypeSlave   = "slave"
	ProviderTypeOther   = "other"
)
View Source
const (
	CapProviderNosqlElasticSearch // elasticSearch能力
)

nosql db ability

View Source
const SdkCategoryOffset = 10 // 底层库能力类别
View Source
const (
	SdkTypeDbMysql
)

database capability

View Source
const (
	SdkTypeGraphNeo4j
)

database capability

View Source
const (
	SdkTypeKvEtcd // etcd能力
)

key/value storage ability

View Source
const (
	SdkTypeLogZerolog
)

log ability

Variables

View Source
var (
	ErrEmptyConfig   = errors.New("empty config")
	ErrInvalidConfig = errors.New("invalid config")
)

Functions

This section is empty.

Types

type BuilderClient added in v1.0.63

type BuilderClient interface {
	ToSql() (string, []any, error)
	HGet(v any) error
	HSelect(v any, args ...*protobuf.ListParam) error
	HCount() (int64, error)
	HQuery(args ...*protobuf.ListParam) (*sqlx.Rows, error)
}

type CacheClient

type CacheClient interface {
	// general purpose
	Del(key string) error
	Dels(keys []string) error
	Exists(key string) (bool, error)
	Expire(key string, expire int) error
	Incr(key string) error
	IncrBy(key string, number int) error
	DecrBy(key string, number int) error
	Ttl(key string) (int64, error)
	Pipeline(commands []*CacheCommand) (reply interface{}, err error)
	Ping() error

	// Set operations
	Set(key string, value interface{}) error
	SetEx(key string, value interface{}, expire int) error

	// Get operations
	Get(key string) ([]byte, error)
	GetInt(key string) (int, error)
	GetInt64(key string) (int64, error)
	GetFloat64(key string) (float64, error)
	GetString(key string) (string, error)

	// HashMap operations
	HGetAll(key string) (map[string]string, error)
	HGet(key string, field string) ([]byte, error)
	HGetInt(key string, field string) (int, error)
	HGetInt64(key string, field string) (int64, error)
	HGetFloat64(key string, field string) (float64, error)
	HGetString(key string, field string) (string, error)
	HMGet(key string, fields []string) ([][]byte, error)
	HSet(key string, field interface{}, value interface{}) (int, error)
	HMSet(key string, args map[string]interface{}) error
	HDel(key string, field interface{}) (int, error)
	HDels(key string, fields []interface{}) (int, error)
	HLen(key string) (int, error)

	// set
	SIsMember(key string, member interface{}) (bool, error)
	SAdd(key string, members interface{}) error
	SRem(key string, members interface{}) error
	SInter(keys []string) ([]string, error)
	SUnion(keys []string) ([]string, error)
	SDiff(keys []string) ([]string, error)
	SMembers(key string) ([]string, error)

	// zset
	ZAdd(key string, score int64, member interface{}) error
	ZCard(key string) (int, error)
	ZRange(key string, min, max int64) (map[string]string, error)
	ZRemRangeByScore(key string, min, max interface{}) error
	ZRangeByScore(key string, min, max interface{}) ([]string, error)
	ZScore(key string, member interface{}) (int64, error)
	ZInterstore(newKey string, keys ...interface{}) (int64, error)
	ZIncrBy(key string, increment int64, member interface{}) error
	ZRem(destKey string, members ...interface{}) (int64, error)

	// list
	LPush(key string, values ...any) error
	RPush(key string, values ...any) error
	RPop(key string) ([]byte, error)
	LRangeInt64(key string, start, end int64) ([]int64, error)
	LRangeString(key string, start, end int64) ([]string, error)
	LLen(key string) (int64, error)
	Eval(scriptContent string, keys []interface{}, args []interface{}) (interface{}, error)

	// redis bloom
	BfExists(key string, item string) (exists bool, err error)
	BfAdd(key string, item string) (exists bool, err error)
	BfReserve(key string, errorRate float64, capacity uint64) (err error)
	BfAddMulti(key string, items []interface{}) ([]int64, error)
	BfExistsMulti(key string, items []interface{}) ([]int64, error)
}

type CacheCommand

type CacheCommand struct {
	Name string
	Args []interface{}
}

type CacheProvider

type CacheProvider interface {
	Provider
	My() CacheClient
	By(string) CacheClient
}

type Configer

type Configer interface {
	GetLogConfig() interface{}      // 日志配置
	GetMysqlConfig() interface{}    // mysql数据库配置
	GetRedisConfig() interface{}    // redis缓存配置
	GetRabbitmqConfig() interface{} // GetRabbitmqConfig 获取RabbitMq队列配置
	GetKafkaConfig() interface{}    // GetKafkaConfig 获取kafka消息队列配置
	GetNosqlConfig() interface{}    // NoSQL服务配置
	GetEtcdConfig() interface{}     // kv型服务配置
	GetGraphConfig() interface{}    // 图数据库配置
}

type DbClient

type DbClient interface {
	SqlxClient
	BuilderClient
	Sq(builder squirrel.Sqlizer) DbClient
	Sqrl(builder sqrl.Sqlizer) DbClient
}

type DbProvider

type DbProvider interface {
	Provider
	My() DbClient       // 默认我们的数据库连接
	Master() DbClient   // 主库
	Slave(int) DbClient // 指定的从库
	By(string) DbClient // 获取某个名字的数据库连接
}

DbProvider database能力提供

type GraphProvider

type GraphProvider interface {
	Provider
	Get(cypher string, args ...interface{}) (interface{}, error)
	Select(cypher string, args ...interface{}) ([]interface{}, error)
	Exec(workFuncs []neo4j.TransactionWork, bookmarks ...string) (string, error)
	Reader(bookmarks ...string) neo4j.Session
	Writer(bookmarks ...string) neo4j.Session
}

GraphProvider 图数据库能力提供

type KvProvider

type KvProvider interface {
	Get(key string) ([]byte, error)
	List(key string) (kv.KVPairs, error)
	Set(key string, value []byte) error
	Watch(key string, stop chan bool) <-chan *kv.Response
}

type LogProvider

type LogProvider interface {
	Provider

	GetStdLogger() *log.Logger

	// Log add go-kit log compatibility
	Log(keyvals ...interface{}) error

	Trace(msg string, keyvals ...interface{})
	Debug(msg string, keyvals ...interface{})
	Info(msg string, keyvals ...interface{})
	Warn(msg string, keyvals ...interface{})
	Error(msg string, keyvals ...interface{})
	Fatal(msg string, keyvals ...interface{})
	Panic(msg string, keyvals ...interface{})
}

type Mq

type Mq interface {
	GetDefaultOptions() map[MqOptionType]MqOptioner
	CreateProducer(parameters map[string]interface{}, args ...MqOptioner) (MqProducer, error)
	CreateConsumer(processFunc MqMsgProcessFunc, parameters map[string]interface{}, args ...MqOptioner) (MqConsumer, error)
}

type MqConsumer

type MqConsumer interface {
	Consume() // 消费消息
	Close()
}

消息订阅者,负责从Topic接收并消费消息。

type MqMsgAction

type MqMsgAction int

MqMsgAction 消息处理后的动作

const (
	Ack        MqMsgAction // 消息标志处理成功
	Retry                  // 消息重传进行重新处理,当条消息会被重传
	Next                   // 取下一条消息
	BatchAck               // 批量消息标志处理成功
	BatchRetry             // 批量消息进行重传并重新处理,自上次ack到现在的消息都会被重传
)

type MqMsgProcessFunc

type MqMsgProcessFunc func([]byte) MqMsgAction

MqMsgProcessFunc MQ的消息处理函数 入参为处理的数据 第一个返回值是否要ack 第二个返回值是否要把同一个channel上的上一次ack之前的所有

type MqOptionType

type MqOptionType int

option types

const (
	MqOptionQueue    MqOptionType // 队列选项
	MqOptionExchange              // exchange选项
	MqOptionPublish               // 发送选项
	MqOptionConsume               // 消费选项
	MqOptionQos                   // Qos选项
)

type MqOptioner

type MqOptioner interface {
	GetType() MqOptionType // 获取配置项类型,现在有几个配置项: exchange配置项, queue配置项, publish配置项
}

MqOptioner 选项接口

type MqProducer

type MqProducer interface {
	Publish(data []byte, args ...interface{}) error                 // MQ发送消息
	PublishDelay(data []byte, ttl int64, args ...interface{}) error // MQ发送延迟消息
	GetLastConfirmedId() uint64                                     // 获取上一次确认发送成功的消息Tag
	Close()
}

消息发布者,负责生产并发送消息至Topic

type MqProvider

type MqProvider interface {
	Provider
	My() Mq
	By(string) Mq // 获取某个Mq能力提供者
}

type NosqlProvider

type NosqlProvider interface {
}

type Provider

type Provider interface {
	Init(rootConfiger Configer, logger LogProvider, args ...interface{}) error // 初始化底层能力
}

Provider 底层库能力提供者接口

type SdkConfigItem

type SdkConfigItem struct {
	Log      interface{} `mapstructure:"log"`      // 日志配置
	Mysql    interface{} `mapstructure:"mysql"`    // 数据库配置
	Redis    interface{} `mapstructure:"redis"`    // 缓存配置
	RabbitMq interface{} `mapstructure:"rabbitmq"` // rabbitmq消息队列配置
	Kafka    interface{} `mapstructure:"kafka"`    // kafka消息队列配置
	Nosql    interface{} `mapstructure:"nosql"`    // NoSQL配置
	Etcd     interface{} `mapstructure:"etcd"`     // etcd Key/Value数据库配置
	Neo4j    interface{} `mapstructure:"neo4j"`    // neo4j数据库配置
}

SdkConfigItem items under sdk config

type SdkType

type SdkType int
const (
	SdkCategoryLog   SdkType // 日志能力
	SdkCategoryDb            // 数据库能力, 例如mysql
	SdkCategoryCache         // 缓存能力,例如redis
	SdkCategoryMq            // 消息队列能力,例如rabbitmq, rocketmq, kafka
	SdkCategoryNosql         // nosql数据库能力,例如es, monodb
	SdkCategoryKv            // kv型数据库能力,例如etcd
	SdkCategoryGraph         // 图数据库能力
)
const (
	SdkTypeCacheRedis SdkType // redis缓存能力
)

cache ability

type SqlxClient added in v1.0.63

type SqlxClient interface {
	sqlx.Ext
	sqlx.ExtContext
	MapperFunc(mf func(string) string)
	Unsafe() *sqlx.DB
	NamedQuery(query string, arg interface{}) (*sqlx.Rows, error)
	NamedExec(query string, arg interface{}) (sql.Result, error)
	Select(dest interface{}, query string, args ...interface{}) error
	Get(dest interface{}, query string, args ...interface{}) error
	MustBegin() *sqlx.Tx
	Beginx() (*sqlx.Tx, error)
	MustExec(query string, args ...interface{}) sql.Result
	Preparex(query string) (*sqlx.Stmt, error)
	PrepareNamed(query string) (*sqlx.NamedStmt, error)
}

Jump to

Keyboard shortcuts

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