go_toolbox

package module
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Apr 25, 2023 License: Apache-2.0 Imports: 17 Imported by: 0

README

go-toolbox

This library is a wrapper for everyday use components 该库是日常使用组件的封装

ToolList

  • Logger -- 日志

    • 基于 uber-go/zap
  • Redis

    • 基于 go-redis/v9
    • 布隆过滤器基于RedisBloom/RedisBloom
  • Clickhouse

    • 基于 clickHouse/clickhouse-go
    • 基于 jmoiron/sqlx

TodoList

  • ✅Redis
  • ✅Logger
  • Kafka
  • Apollo
  • Prometheus
  • MYSQL
  • ✅ClickHouse
  • MinIO
  • ....

Documentation

Index

Constants

View Source
const (
	ClientMaxBlockSize        int = 100000
	ClientReadTimeout         int = 90
	ClientReadTimeoutDuration     = 90 * time.Second
)
View Source
const (
	NilType      = redis.Nil
	PoolSize int = 800
	MinIdles int = 50
)
View Source
const LogConsoleSeparator string = "|-|"

LogConsoleSeparator 分隔符

Variables

View Source
var Logger *zap.Logger

Functions

func GetLogPrefix

func GetLogPrefix(traceId string, msgList ...string) string

func NewZapLogger

func NewZapLogger(filename string, maxSize int, maxBackups int, maxAge int, compress bool)

NewZapLogger 初始化 Zap Logger

Types

type CKHandler

type CKHandler struct {
	ClickhouseConf

	InsertSql string
	// contains filtered or unexported fields
}

func NewCKHandler

func NewCKHandler(ckConf *ClickhouseConf) *CKHandler

func (*CKHandler) BatchInsertData

func (c *CKHandler) BatchInsertData(query string, dataArrays [][]interface{}) (bool, error)

func (*CKHandler) InitClickHouse

func (c *CKHandler) InitClickHouse()

func (*CKHandler) InitInsertSQL

func (c *CKHandler) InitInsertSQL()

func (*CKHandler) InsertData

func (c *CKHandler) InsertData(query string, data ...interface{}) (bool, error)

func (*CKHandler) QueryData

func (c *CKHandler) QueryData(items interface{}, query string) error

type ClickhouseConf

type ClickhouseConf struct {
	Host       string   `json:"Host"`
	Port       int      `json:"Port"`
	Username   string   `json:"Username"`
	Password   string   `json:"PassWord"`
	Database   string   `json:"DataBase"`
	Table      string   `json:"Table"`
	DataSchema []string `json:"DataSchema"`
}

type ModelRedisHandler

type ModelRedisHandler struct {
	RedisConf
	RedisClient        *redis.Client
	RedisClusterClient *redis.ClusterClient
}

func NewRedisHandler

func NewRedisHandler(redisConf *RedisConf) *ModelRedisHandler

func (*ModelRedisHandler) AppendList

func (r *ModelRedisHandler) AppendList(key string, value interface{}) bool

func (*ModelRedisHandler) BFAdd

func (r *ModelRedisHandler) BFAdd(key string, value string) (bool, bool)

func (*ModelRedisHandler) BFExists

func (r *ModelRedisHandler) BFExists(key string, value string) bool

func (*ModelRedisHandler) EmptyList

func (r *ModelRedisHandler) EmptyList(key string) bool

func (*ModelRedisHandler) Get

func (r *ModelRedisHandler) Get(key string) (string, bool)

func (*ModelRedisHandler) GetList

func (r *ModelRedisHandler) GetList(key string, start, stop int64) ([]string, bool)

func (*ModelRedisHandler) HashDel

func (r *ModelRedisHandler) HashDel(key string, fields ...string) bool

func (*ModelRedisHandler) HashGet

func (r *ModelRedisHandler) HashGet(key, field string) (string, bool)

func (*ModelRedisHandler) HashLen

func (r *ModelRedisHandler) HashLen(key string) int64

func (*ModelRedisHandler) HashMGET

func (r *ModelRedisHandler) HashMGET(key string, fields ...string) ([]interface{}, bool)

func (*ModelRedisHandler) HashMSet

func (r *ModelRedisHandler) HashMSet(key string, values ...interface{}) bool

func (*ModelRedisHandler) HashSet

func (r *ModelRedisHandler) HashSet(key string, values ...interface{}) bool

HashSet accepts values in following formats:

  • HashSet("myhash", "key1", "value1", "key2", "value2")
  • HashSet("myhash", []string{"key1", "value1", "key2", "value2"})
  • HashSet("myhash", map[string]interface{}{"key1": "value1", "key2": "value2"})

Note that it requires Redis v4 for multiple field/value pairs support.

func (*ModelRedisHandler) Pipeline

func (r *ModelRedisHandler) Pipeline() (redis.Pipeliner, context.Context)

Pipeline pipeline

func (*ModelRedisHandler) PipelineExecute

func (r *ModelRedisHandler) PipelineExecute(pipe redis.Pipeliner, ctx context.Context) ([]redis.Cmder, error)

PipelineExecute pipeline 执行

func (*ModelRedisHandler) Set

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

func (*ModelRedisHandler) ShutdownRedisHandler

func (r *ModelRedisHandler) ShutdownRedisHandler() error

ShutdownRedisHandler 关闭 Redis 连接

type RedisConf

type RedisConf struct {
	Host      string `json:"Host"`
	Password  string `json:"Password"`
	Database  int    `json:"Database"`
	IsCluster bool   `json:"IsCluster"`
	Enable    bool   `json:"Enable"`
}

type ZapLogger

type ZapLogger struct {
	Filename   string
	MaxSize    int
	MaxBackups int
	MaxAge     int
	Compress   bool
}

Jump to

Keyboard shortcuts

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