types

package
v1.0.37 Latest Latest
Warning

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

Go to latest
Published: Aug 12, 2023 License: MPL-2.0 Imports: 4 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ENV_PRODUCTION     = "prod"
	ENV_PRE_PRODUCTION = "pre"
	ENV_SIMULATION     = "sim"
	ENV_TEST           = "test"
	ENV_DEV            = "dev"
	ENV_LOCAL          = "local"
)

环境变量的参数

View Source
const (
	PROVIDER_TYPE_DEFAULT = "default"
	PROVIDER_TYPE_MASTER  = "master"
	PROVIDER_TYPE_SLAVE   = "slave"
	PROVIDER_TYPE_OTHER   = "other"
)
View Source
const (
	CAP_PROVIDER_KV_ETCD // etcd能力
)

key/value storage ability

View Source
const (
	CAP_PROVIDER_NOSQL_ES // elasticSearch能力
)

nosql db ability

View Source
const SdkCategoryOffset = 10

底层库能力类别

Variables

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

所有支持的环境

Functions

This section is empty.

Types

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
	RPop(key string) ([]byte, 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服务配置
	GetKvConfig() interface{}       // kv型服务配置
	GetGraphConfig() interface{}    // 图数据库配置
}

type DbClient

type DbClient interface {
	// Rebind transforms a query from QUESTION to the DB driver's bindvar type.
	Rebind(query string) string

	Get(dest interface{}, query string, args ...interface{}) error
	Queryx(query string, args ...interface{}) (*sqlx.Rows, error)
}

type DbProvider

type DbProvider interface {
	Provider

	My() *sqlx.DB // 默认我们的数据库连接
	Master() *sqlx.DB
	Slave(int) *sqlx.DB
	By(string) *sqlx.DB // 获取某个名字的数据库连接
}

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 {
}

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

消息处理后的动作

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

type MqMsgProcessFunc

type MqMsgProcessFunc func([]byte) MqMsgAction

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配置项
}

选项接口

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 // 初始化底层能力
}

底层库能力提供者接口

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消息队列配置
	MicroService interface{} `mapstructure:"service"`  // 基于gokit实现的微服务配置, ms means microservice
	Nosql        interface{} `mapstructure:"nosql"`    // NoSQL配置
	Kv           interface{} `mapstructure:"kv"`       // Key/Value数据库配置
	Neo4j        interface{} `mapstructure:"neo4j"`    // neo4j数据库配置
}

items under sdk config

type SdkType

type SdkType int
const (
	SdkTypeMqRabbitmq SdkType // rabbitmq消息队列能力
	SdkTypeMqKafka            // kafka
)

message queue provider

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

log ability

const (
	SdkTypeCacheRedis SdkType // redis缓存能力
)

cache ability

const (
	SdkTypeDbMysql SdkType
)

database capability

const (
	SdkTypeGraphNeo4j SdkType
)

database capability

Jump to

Keyboard shortcuts

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