common

package
v0.0.0-...-a604d9f Latest Latest
Warning

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

Go to latest
Published: May 24, 2021 License: BSD-3-Clause Imports: 18 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// Redis 键名值分隔符, 默认为冒号
	RedisKeySep = ":"

	// Redis 键名时间格式
	RedisKeyTime = "060102150405"

	// Redis 全局锁键名前缀
	RedisLockKey = "DR:REDISLOCK:"

	// 待办调度锁
	RedisLockTodoKey = "DR:TODOLOCK"

	TodoListKey    = "DR:TODO:LIST"
	SrcTagKey      = ":SRC:list:"
	TodoTagKey     = ":TODO:list:"
	PostTagKey     = ":POST:list"
	PostTodoTagKey = ":GoPOST:list:"
)

Variables

View Source
var (
	IPv4Zero = "0.0.0.0"
	// ES 系统字段
	ESSYSField = [...]string{"_cip", "_ctime", "_gtime"}
	// 空白字符替换器
	SpaceReplacer = strings.NewReplacer(
		"\n", "",
		"\r", "",
		"\f", "",
		"\v", "",
		"\t", "",
		"\u0085", "",
		"\u00a0", "",
	)
	// 协程池
	Pool = goroutine.Default()
)
View Source
var (
	Log        zerolog.Logger
	LogSampled zerolog.Logger
)
View Source
var ES *elasticsearch.Client
View Source
var GTimeSub time.Duration
View Source
var RedisDB *redis.Client
View Source
var RenameScript = redis.NewScript(`
			if redis.call("exists", KEYS[1]) == 1 then
				redis.call("rename", KEYS[1], ARGV[1])
				redis.call("expire", ARGV[1], ARGV[2])
				return 1
			else
				return 0
			end
	`)

Functions

func AppendSYSField

func AppendSYSField(data, sysField string) string

附加系统字段

func CheckRequiredField

func CheckRequiredField(body []byte, fields []string) bool

检查必有字段

func Clean

func Clean()

程序退出时清理

func GetGlobalDataTime

func GetGlobalDataTime(layout string) string

统一时间: Redis 时间并格式化

func GetGlobalTime

func GetGlobalTime() time.Time

统一时间: Redis 时间

func GetRedisTime

func GetRedisTime() time.Time

获取 Redis 时间作为原子钟

func GetUDPESIndex

func GetUDPESIndex(body []byte, key string) string

获取 ES 索引名称, 不能包含冒号(Redis键分隔符)

func InitES

func InitES() error

func InitLogger

func InitLogger() error

func InitRedisDB

func InitRedisDB() error

func IsValidJSON

func IsValidJSON(data string) (string, bool)

检查是否为正确的 JSON (字典)

func LogConfig

func LogConfig() error

日志配置 1. 开发环境时, 日志高亮输出到控制台 2. 生产环境时, 日志输出到文件(可选关闭高亮, 保存最近 10 个 30 天内的日志)

Types

type TAPIData

type TAPIData struct {
	ID    int         `json:"id"`
	OK    int         `json:"ok"`
	Code  int         `json:"code"`
	Msg   string      `json:"msg"`
	Data  interface{} `json:"data"`
	Count int         `json:"count"`
}

API 标准返回, 内部规范 id: 1, ok: 1, code: 0 成功; id: 0, ok: 0, code: 1 失败 成功时 msg 必定为空

func APIFailureData

func APIFailureData(msg string) *TAPIData

API 请求失败返回值

func APISuccessData

func APISuccessData(data interface{}, count int) *TAPIData

API 请求成功返回值

type TAnyMaps

type TAnyMaps map[interface{}]interface{}

type TStringAnyMaps

type TStringAnyMaps map[string]interface{}

Jump to

Keyboard shortcuts

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