pocket

package module
v0.0.5 Latest Latest
Warning

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

Go to latest
Published: Apr 17, 2020 License: MIT Imports: 24 Imported by: 0

README

pocket

golang tools

Documentation

Overview

Package pocket @author K·J Create at 2019-04-09 15:09

Package pocket @author K·J Create at 2019-04-09 15:11

Package pocket @author K·J Create at 2019-04-09 15:14

Package pocket @author K·J Create at 2019-04-15 15:04

Package log @author K·J Create at 2019-05-15 15:03

Package pocket K·J Create at 2020-04-09 21:30

Package pocket K·J Create at 2020-04-09 21:36

Package pocket K·J Create at 2020-04-09 21:09

Package pocket @author K·J Create at 2019-04-09 15:13

Package pocket @author K·J Create at 2019-04-09 15:10

Index

Constants

This section is empty.

Variables

View Source
var DefaultLogger = &Logback{
	logger: log.New(os.Stdout, "", defaultFlag),
	fields: nil,
	level:  InfoLevel,
}

Functions

func Any added in v0.0.3

func Any(condition func(interface{}) bool, args ...interface{}) bool

func CreateCaptcha

func CreateCaptcha(digit int) string

CreateCaptcha random

func DecodeQuery added in v0.0.3

func DecodeQuery(dst interface{}, src map[string][]string) error

DecodeQuery decode get query

func Decrypt

func Decrypt(cipherText, key []byte) ([]byte, error)

Decrypt aes Decrypt

func Diff added in v0.0.3

func Diff(origin interface{}, current interface{}) (string, string)

Diff compile 2objects

func Each added in v0.0.3

func Each(action func(interface{}), args ...interface{})

func Encrypt

func Encrypt(plantText, key []byte) ([]byte, error)

Encrypt aes Encrypt

func Filter added in v0.0.3

func Filter(condition func(int, interface{}) bool, data interface{}) (interface{}, error)

func GetLogger added in v0.0.3

func GetLogger() *logrus.Logger

func GetUUID

func GetUUID() uuid.UUID

GetUUID gene uuid

func InfluxQueryRow

func InfluxQueryRow(c *client.Client, query client.Query) (*models.Row, error)

InfluxQueryRow query row from influx

func Md5

func Md5(txt string) string

md5 md5 32 lowercase

func NewContextHook added in v0.0.3

func NewContextHook(levels ...logrus.Level) logrus.Hook

NewContextHook use to make an hook

func NilCondition added in v0.0.3

func NilCondition(i interface{}) bool

func PKCS7Padding

func PKCS7Padding(cipherText []byte, blockSize int) []byte

PKCS7Padding aes pkcs

func PKCS7UnPadding

func PKCS7UnPadding(plantText []byte) []byte

PKCS7UnPadding aes pkcs

func ReqToSql added in v0.0.3

func ReqToSql(model interface{}) (string, []interface{}, map[string][]string, error)

ReqToSql 查询列表时,将req转换为where查询条件及sort排序,仅支持单表

func SnakeString added in v0.0.3

func SnakeString(s string) string

SnakeString, XxYy to xx_yy , XxYY to xx_yy

func Stom

func Stom(columns []string) map[int]string

Stom convert []string to map[int]string

func String added in v0.0.3

func String(model interface{}) string

func ToArray added in v0.0.3

func ToArray(array interface{}) []interface{}

[]class -> []interface{}

func ToString added in v0.0.3

func ToString(origin interface{}, tag, joiner, separator string) string

func UnixMillisecond

func UnixMillisecond() int64

UnixMillisecond unix time millisecond

func UnixSecond

func UnixSecond() int64

UnixSecond unix time second

func UnmarshalInflux

func UnmarshalInflux(columns map[int]string, data []interface{}, v interface{}) error

UnmarshalInflux convert influx db row to struct columns [index]:[column name] data row of values v struct tag:'influx'

func XormUpdateParam added in v0.0.3

func XormUpdateParam(model interface{}) (map[string]interface{}, error)

Types

type Api

type Api interface {
	Info(v ...interface{})
	Debug(v ...interface{})
	Warn(v ...interface{})
	Error(v ...interface{})
	Trace(v ...interface{})
}

type Code

type Code struct {
	Code int    `json:"code"`
	Msg  string `json:"msg"`
}

Code object

func NewCode

func NewCode(code int, msg string) *Code

NewCode get object

func (*Code) Error

func (c *Code) Error() string

Code to json

type ContextHook added in v0.0.3

type ContextHook struct {
	Field string
	Skip  int
	// contains filtered or unexported fields
}

ContextHook for log the call context

func (ContextHook) Fire added in v0.0.3

func (hook ContextHook) Fire(entry *logrus.Entry) error

Fire implement fire

func (ContextHook) Levels added in v0.0.3

func (hook ContextHook) Levels() []logrus.Level

Levels implement levels

type Fields

type Fields map[string]interface{}

type Level

type Level uint32

Level type

const (
	// PanicLevel level, highest level of severity. Logs and then calls panic with the
	// message passed to Debug, Info, ...
	PanicLevel Level = iota
	// FatalLevel level. Logs and then calls `logger.Exit(1)`. It will exit even if the
	// logging level is set to Panic.
	FatalLevel
	// ErrorLevel level. Logs. Used for errors that should definitely be noted.
	// Commonly used for hooks to send errors to an error tracking service.
	ErrorLevel
	// WarnLevel level. Non-critical entries that deserve eyes.
	WarnLevel
	// InfoLevel level. General operational entries about what's going on inside the
	// application.
	InfoLevel
	// DebugLevel level. Usually only enabled when debugging. Very verbose logging.
	DebugLevel
	// TraceLevel level. Designates finer-grained informational events than the Debug.
	TraceLevel
)

type Logback

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

func (*Logback) Debug

func (logback *Logback) Debug(v ...interface{})

func (*Logback) Error

func (logback *Logback) Error(v ...interface{})

func (*Logback) Info

func (logback *Logback) Info(v ...interface{})

func (*Logback) SetLevel

func (logback *Logback) SetLevel(level Level)

func (*Logback) SetOutput

func (logback *Logback) SetOutput(w io.Writer)

func (*Logback) Trace

func (logback *Logback) Trace(v ...interface{})

func (*Logback) Warn

func (logback *Logback) Warn(v ...interface{})

func (*Logback) WithFields

func (logback *Logback) WithFields(fields Fields) *Logback

type RedisConfig added in v0.0.3

type RedisConfig struct {
	Host       string
	Pwd        string
	ExpireTime int
}

RedisConfig redis config

type RedisUtils added in v0.0.3

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

func NewRedis added in v0.0.3

func NewRedis(config RedisConfig) (*RedisUtils, error)

NewRedis get redis client

func (*RedisUtils) Close added in v0.0.3

func (r *RedisUtils) Close()

Close close redis connect

type Resp

type Resp struct {
	Code
	Data interface{} `json:"data"`
}

Resp common response

func NewResp

func NewResp(error *Code, data interface{}) Resp

NewResp param to Object

func (*Resp) Marshal

func (resp *Resp) Marshal() []byte

Marshal to json []byte

type SqlBuilder added in v0.0.3

type SqlBuilder struct {
	Table string
	Model interface{}
}

func NewSqlBuilder added in v0.0.3

func NewSqlBuilder(table string, model interface{}) *SqlBuilder

NewSqlBuilder sql builder tag规则 `db:"column,add,set,sort"`

func (*SqlBuilder) BuildInsert added in v0.0.3

func (builder *SqlBuilder) BuildInsert() (string, []interface{}, error)

BuildInsert 生成批量插入sql

func (*SqlBuilder) BuildInsertRow added in v0.0.3

func (builder *SqlBuilder) BuildInsertRow() (string, []interface{}, error)

BuildInsertRow 生成单条插入sql

Jump to

Keyboard shortcuts

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