Documentation ¶
Index ¶
- Constants
- Variables
- type CacheClient
- type CacheCommand
- type CacheProvider
- type Configer
- type DbClient
- type DbProvider
- type GrpcAspect
- type GrpcClientManager
- type GrpcServerManager
- type HttpAspect
- type HttpServerManager
- type KvProvider
- type LogProvider
- type MicroService
- type Mq
- type MqConsumer
- type MqMsgAction
- type MqMsgProcessFunc
- type MqOptionType
- type MqOptioner
- type MqProducer
- type MqProvider
- type MsProvider
- type NosqlProvider
- type Provider
- type SdkConfigItem
- type SdkType
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 ( MqTypeDirect = "direct" MqTypeFanout = "fanout" MqTypeTopic = "topic" )
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") )
View Source
var SupportedEnvs = []string{ ENV_PRODUCTION, ENV_PRE_PRODUCTION, ENV_SIMULATION, ENV_TEST, ENV_DEV, ENV_LOCAL, }
所有支持的环境
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 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 get 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) // 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) // list RPop(key string) ([]byte, 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型服务配置 GetMicroServiceConfig() interface{} // gokit微服务配置 }
type DbProvider ¶
type DbProvider interface { Provider My() *sqlx.DB // 默认我们的数据库连接 Master() *sqlx.DB Slave(int) *sqlx.DB By(string) *sqlx.DB // 获取某个名字的数据库连接 }
database能力提供
type GrpcAspect ¶
type GrpcAspect interface { GetServiceName() string GetMethodName() string // MakeEndpoint 解析request, 调用服务函数, 封装成endpoint MakeEndpoint(svc interface{}) endpoint.Endpoint // ServerDecodeRequest server side convert grpc request to domain request ServerDecodeRequest(ctx context.Context, request interface{}) (interface{}, error) // ServerEncodeResponse server side encode response to domain response ServerEncodeResponse(ctx context.Context, response interface{}) (interface{}, error) // GetGrpcReplyType 获取Grpc返回类型 GetGrpcReplyType() interface{} // ClientEncodeRequest server side convert grpc request to domain request ClientEncodeRequest(ctx context.Context, request interface{}) (interface{}, error) // ClientDecodeResponse server side convert grpc request to domain request ClientDecodeResponse(ctx context.Context, request interface{}) (interface{}, error) }
GrpcAspect Grpc切面
type GrpcClientManager ¶
type GrpcClientManager interface { CreateConnection(args ...grpc.DialOption) (*grpc.ClientConn, error) CreateEndpoint(conn *grpc.ClientConn, ap GrpcAspect) endpoint.Endpoint }
type GrpcServerManager ¶
type HttpAspect ¶
type HttpAspect interface { GetMethodName() string // MakeEndpoint 解析request, 调用服务函数, 封装成endpoint MakeEndpoint(svc interface{}) endpoint.Endpoint // ServerDecodeRequest server side convert grpc request to domain request ServerDecodeRequest(ctx context.Context, request *http.Request) (interface{}, error) // ServerEncodeResponse server side encode response to domain response ServerEncodeResponse(context.Context, http.ResponseWriter, interface{}) error }
HttpAspect HttpAspect
type HttpServerManager ¶
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 MicroService ¶
type MicroService interface { NewGrpcServerManager() GrpcServerManager NewGrpcClientManager() GrpcClientManager NewHttpServerManager() HttpServerManager }
type Mq ¶
type Mq interface { GetDefaultOptions() map[MqOptionType]MqOptioner CreateProducer(name string, args ...map[MqOptionType]MqOptioner) (MqProducer, error) CreateConsumer(name string, processFunc MqMsgProcessFunc, args ...map[MqOptionType]MqOptioner) (MqConsumer, error) }
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发送消息 GetLastConfirmedId() uint64 // 获取上一次确认发送成功的消息Tag Close() }
消息发布者,负责生产并发送消息至Topic
type MsProvider ¶
type MsProvider interface { My() MicroService By(name string) MicroService }
MsProvider MS: microservice
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:"aliyun"` // 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数据库配置 }
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 )
const (
LibLogZerolog SdkType
)
log ability
const (
SdkTypeCacheRedis SdkType // redis缓存能力
)
cache ability
const (
SdkTypeDbMysql SdkType
)
database capability
const (
SdkTypeMsGokit SdkType // 基于Gokit的微服务能力
)
message queue provider
Click to show internal directories.
Click to hide internal directories.