dbcommon

package
v0.0.6 Latest Latest
Warning

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

Go to latest
Published: Jan 31, 2023 License: MIT Imports: 26 Imported by: 0

Documentation

Index

Constants

View Source
const (
	MessagedbDatabase registryName
	MessagedbShardDatabase
	MessagedbEncryDatabase
	MessagedbOldDatabase
	MessagedbPtsHandleDatabase

	ChanneldbDatabase
	ChanneldbMsgShardDatabase
	ChanneldbEncryDatabase
	ChanneldbOldDatabase
	ChanneldbPtsHandleDatabase

	PotatoDcConfigDatabase

	PotatoAccountDatabase
	PotatoUserDatabase
	PotatoChannelDatabase
	PotatoGroupDatabase
	PotatoMonitorDatabase
	PotatoCommonDatabase
	PotatoAppliedDatabase
	PotatoSecurityChatDatabase
	PotatoPrivateChatHistoryDatabase
	PotatoSecurityChatDiffMessageDatabase
	PotatoConfigDatabase
	PotatoProxyConfigDatabase
	PotatoUserGpsDatabase
	PotatoUserBot // schema potato_user_bot
	PotatoUserSessionDatabase
	PotatoEmailDatabase
	GeoDatabase
	OpenPlatformMgrDatabase
	GameApiDatabase
	ShortVideoDatabase
	PayServerMysql
	// ========================= redis =========================
	MessageRedis
	MessageShardRedis
	MessageRedisScri //= "messageRe"
	UserInfoRedis
	AuthorizationRedis // 用户session redis
	BasicGroupRedis    // 普通群、超级群信息专用redis
	MediaPushRedis
	MediaPullRedis
	MesageIncreaseRedis
	SecrityChatRedis                 = MessageRedis
	ChannelMessageRedis registryName = 4000 + iota
	ChannelMessageShardRedis
	GeoRedis
	OpenPlatformRedis
	GameApiRedis
	ShortVideoRedis
	PayServerRedis
	// ========================= nats =========================
	PtNats
	PtRouteNats
	PtMemNats
	PtMomentNats
	PtCircleFriend

	// ========================= es =========================
	PtRedisES
	Unknown
)

Variables

This section is empty.

Functions

func Close

func Close()

func CloseKafka

func CloseKafka()

func GetCRDBInfo

func GetCRDBInfo(platform string) (*cockdbInfo, bool)

func GetDatabase

func GetDatabase(dbName registryName) *xorm.EngineGroup

************************ base function ******************

func GetESConn

func GetESConn(esName registryName) *elastic.Client

func GetEtcdPlatformInfo

func GetEtcdPlatformInfo(platform string) ([]string, error)

func GetKafkaInfoFromLinkMap

func GetKafkaInfoFromLinkMap(platform string) *kafkaInfoConfig

func GetMysqlInfoFromLinkMap

func GetMysqlInfoFromLinkMap(platform string) *mysqlInfoConfig

func GetNatsConn

func GetNatsConn(natsName registryName) *nats.Conn

func GetPayserverCfgFromLinkMap

func GetPayserverCfgFromLinkMap(platform string) *payserverCfgConfig

func GetRedisCluster

func GetRedisCluster(redisName registryName) *redis.ClusterClient

func GetRedisInfoFromLinkMap

func GetRedisInfoFromLinkMap(platform string) *redisInfoConfig

func GetZrangeBy

func GetZrangeBy(min, max string, offset, limit int64) redis.ZRangeBy

func HandleNatsConfigFields

func HandleNatsConfigFields(cfgs ...*NatsConfig) error

func HandleRedisConfigEncryFields

func HandleRedisConfigEncryFields(cfgs ...*RedisConfig) error

func HandleRedisConfigWithDefault

func HandleRedisConfigWithDefault(defaultCfg RedisConfig, cfgs ...*RedisConfig)

func HandleXormConfigEncryFields

func HandleXormConfigEncryFields(cfgs ...*XormConfig) error

func HandleXormConfigWithDefault

func HandleXormConfigWithDefault(defaultCfg XormDefaultConfig, cfgs ...*XormGroupConfig)

func HandleXormGroupConfigEncryFields

func HandleXormGroupConfigEncryFields(cfgs ...*XormGroupConfig) error

func InitLinkMap

func InitLinkMap(cfg *XormGroupConfig) error

func InitLinkMapByDataSourceName

func InitLinkMapByDataSourceName(dataSourceName string) error

func InitializeEtcdLinkMap

func InitializeEtcdLinkMap(driver, source string) error

func InitializeMysqlLinkMap

func InitializeMysqlLinkMap(driver, src string) error

func InitializeNatsLinkMap

func InitializeNatsLinkMap(driver, src string) error

func MakeMarshal

func MakeMarshal(model interface{}) (interface{}, error)

序列化

func MakeUnmarshal

func MakeUnmarshal(bin []byte, model interface{}) error

反序列化

func NewESClientByCfg

func NewESClientByCfg(cfg ESConfig) (cli *elastic.Client, err error)

func NewNatsClusterByCfg

func NewNatsClusterByCfg(cfg NatsConfig) (*nats.Conn, error)

func NewRedisEngine

func NewRedisEngine(cfg RedisConfig) (*redis.ClusterClient, error)

func NewXormEngine

func NewXormEngine(cfg XormConfig) (*xorm.Engine, error)

func NewXormEngineGroup

func NewXormEngineGroup(cfg XormGroupConfig) (*xorm.EngineGroup, error)

func RegisterDatabase

func RegisterDatabase(dbName registryName, db *xorm.EngineGroup)

func RegisterES

func RegisterES(esName registryName, cli *elastic.Client)

func RegisterNats

func RegisterNats(natsName registryName, n *nats.Conn)

func RegisterRedis

func RegisterRedis(redisName registryName, r *redis.Client)

func RegisterRedisCluster

func RegisterRedisCluster(redisName registryName, r *redis.ClusterClient)

func RegisterRedisScriptCli

func RegisterRedisScriptCli(redisName registryName, r *RedisScriptCli)

func RsaDecrypt

func RsaDecrypt(str string) (string, error)

func StartWrite

func StartWrite(ok bool)

func WithSenderDefaultConfig

func WithSenderDefaultConfig() *sarama.Config

Types

type ESConfig

type ESConfig struct {
	Url      string `yaml:"Url"`
	User     string `yaml:"User"`
	Password string `yaml:"Password"`
	Open     bool   `yaml:"Open"`
}

type EtcdConfig

type EtcdConfig struct {
	// platform
	Platform string `yaml:"Platform"`
	// Endpoints is a list of URLs.
	Endpoints []string `yaml:"Endpoints"`

	// AutoSyncInterval is the interval to update endpoints with its latest members.
	// 0 disables auto-sync. By default auto-sync is disabled.
	AutoSyncInterval time.Duration `yaml:"AutoSyncInterval"`

	// DialTimeout is the timeout for failing to establish a connection.
	DialTimeout time.Duration `yaml:"DialTimeout"`

	// Username is a username for authentication.
	Username string `yaml:"Username"`

	// Password is a password for authentication.
	Password string `yaml:"Password"`
}

type EtcdLinkInfo

type EtcdLinkInfo struct {
	Platform string `yaml:"Platform"`
	HostInfo string `yaml:"HostInfo"`
}

type LinkInfo

type LinkInfo struct {
	UserName   string // 用户名
	UserPasswd string // 密码
	HostInfo   string // 链接信息,格式ip:port
	Platform   string // 所属业务
}

func GetMysqlPlatformInfo

func GetMysqlPlatformInfo(platform string) (*LinkInfo, bool)

type MicroserviceConfig

type MicroserviceConfig struct {
	ServerName string `yaml:"ServerName"`
	MaxMsgSize int    `yaml:"MaxMsgSize"`
}

type NatsConfig

type NatsConfig struct {
	Platform      string `yaml:"Platform"`
	Url           string `yaml:"Url"`
	User          string `yaml:"User"`
	Password      string `yaml:"Password"`
	MaxReconnects int    `yaml:"MaxReconnects"`
	ReconnectWait int    `yaml:"ReconnectWait"`
}

type NatsLinkInfo

type NatsLinkInfo struct {
	UserName string
	Passwd   string
	HostInfo string
	Platform string
}

func GetNatsPlatformInfo

func GetNatsPlatformInfo(platform string) (*NatsLinkInfo, bool)

type RedisConfig

type RedisConfig struct {
	redis.ClusterOptions
	Platform           string        `yaml:"Platform"`
	Addrs              []string      `yaml:"Addrs"`
	MaxRedirects       int           `yaml:"MaxRedirects"`
	ReadOnly           bool          `yaml:"ReadOnly"`
	RouteByLatency     bool          `ymal:"RouteByLatency"`
	RouteRandomly      bool          `yaml:"RouteRandomly"`
	MaxRetries         int           `yaml:"MaxRetries"`
	IdleTimeout        int64         `yaml:"IdleTimeout"` // 过期时间 单位 分钟 默认5分钟
	Password           string        `yaml:"Password"`
	PoolSize           int           `yaml:"PoolSize"`
	LuaScriptDir       string        `yaml:"LuaScriptDir"`       // lua 脚本路径
	IdleCheckFrequency time.Duration `yaml:"IdleCheckFrequency"` // 1h1m1.003002s

}

type RedisScriptCli

type RedisScriptCli struct {
	Cli *redis.ClusterClient
	// contains filtered or unexported fields
}

************************ * author: Dev0026 * createTime: 19-4-2 * updateTime: 19-4-2 * description: ************************

func GetRedisScriptCli

func GetRedisScriptCli(redisName registryName) *RedisScriptCli

func NewRedisScriptCli

func NewRedisScriptCli(cli *redis.ClusterClient) *RedisScriptCli

func (*RedisScriptCli) Eval

func (cc *RedisScriptCli) Eval(dir, luaFileName string, keys []string, args ...interface{}) (interface{}, error)

func (*RedisScriptCli) EvalSha

func (cc *RedisScriptCli) EvalSha(luaFileName string, keys []string, args ...interface{}) (interface{}, error)

func (*RedisScriptCli) LoadScriptFile

func (cc *RedisScriptCli) LoadScriptFile(fileName string) (string, error)

func (*RedisScriptCli) LoadScripts

func (cc *RedisScriptCli) LoadScripts(dir string) error

type SendToPotato

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

func NewSendToPotato

func NewSendToPotato(maxPerSec int32, fn func(string)) *SendToPotato

func NewSendToPotatoWithLevel

func NewSendToPotatoWithLevel(maxPerSec int32, enableLeve zapcore.Level, fn func(string)) *SendToPotato

func (*SendToPotato) EnableLevel

func (s *SendToPotato) EnableLevel(level zapcore.Level)

func (*SendToPotato) Sync

func (s *SendToPotato) Sync() error

func (*SendToPotato) Write

func (s *SendToPotato) Write(b []byte) (n int, er error)

type Sender

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

############### kafka Sender(异步) ###############

func NewSender

func NewSender(addrs ...string) (*Sender, error)

NewSender 创建一个异步kafka

func (*Sender) OnError

func (s *Sender) OnError(errFunc func(*sarama.ProducerError))

sender 错误时

func (*Sender) OnSuccess

func (s *Sender) OnSuccess(succFunc func(*sarama.ProducerMessage))

sender 成功时

func (*Sender) Send

func (s *Sender) Send(topic, key string, data []byte)

sender 发送

type XormConfig

type XormConfig struct {
	SchemaName          string `yaml:"SchemaName"`
	Platform            string `yaml:"Platform"`
	DriverName          string `yaml:"DriverName"`          // 数据库类型 mysql tidb
	DataSourceName      string `yaml:"DataSourceName"`      // 数据库连接
	MaxIdleConns        int    `yaml:"MaxIdleConns"`        // 最大空闲连接数
	MaxOpenConns        int    `yaml:"MaxOpenConns"`        // 最大连接数
	ShowSql             bool   `yaml:"ShowSql"`             // 是否打印sql
	LogLevel            int    `yaml:"LogLevel"`            // xorm 日志级别  LOG_DEBUG: 0 LOG_INFO: 1 LOG_WARNING: 2  LOG_ERR: 3 LOG_OFF: 4 LOG_UNKNOWN: 5
	SqlMapOptionRootDir string `yaml:"SqlMapOptionRootDir"` // sql 文件根目录
	SqlTemplateDir      string `yaml:"SqlTemplateDir"`      // sql 文件目录
	ParamStr            string `yaml:"ParamStr"`            // 连接参数 exp: chatset=utf8mb4
}

type XormDefaultConfig

type XormDefaultConfig struct {
	GroupPolicy       string     `yaml:"GroupPolicy"`       // 负载策略
	GroupPolicyWeight []int      `yaml:"GroupPolicyWeight"` // 权重负载策略 对应值
	XormConfig        XormConfig `yaml:"XormConfigs"`       // xorm具体配置
}

type XormEngineGroupPolicy

type XormEngineGroupPolicy int
const (
	RandomPolicy           XormEngineGroupPolicy = iota // 随机访问负载策略
	WeightRandomPolicy                                  // 权重随机访问负载策略
	RoundRobinPolicy                                    // 轮询访问负载策略
	WeightRoundRobinPolicy                              // 权重轮询访问负载策略
)

func (XormEngineGroupPolicy) String

func (i XormEngineGroupPolicy) String() string

type XormGroupConfig

type XormGroupConfig struct {
	GroupPolicy       string       `yaml:"GroupPolicy"`       // 负载策略
	GroupPolicyWeight []int        `yaml:"GroupPolicyWeight"` // 权重负载策略 对应值
	XormConfigs       []XormConfig `yaml:"XormConfigs"`       // xorm具体配置
}

type ZapLoggerConfig

type ZapLoggerConfig struct {
	Level zapcore.Level `yaml:"Level"`
	Dir   string        `yaml:"Dir"`
}

Jump to

Keyboard shortcuts

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