common

package
v1.1.27 Latest Latest
Warning

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

Go to latest
Published: Mar 21, 2022 License: Apache-2.0 Imports: 32 Imported by: 0

Documentation

Index

Constants

View Source
const (
	EnvDev        = "dev"
	EnvTest       = "test"
	EnvProduction = "prod"
)

定义环境的常量

View Source
const (
	// FormatDefault 默认的日期时间格式
	FormatDefault = "2006-01-02 15:04:05"
	// FormatYYYYMMDD 日期时间格式
	FormatYYYYMMDD = "20060102 15:04:05"
	// FormatYMDH 日期格式
	FormatYMDH = "2006010215"
	// FormatYMD 日期格式
	FormatYMD = "2006-01-02"
)
View Source
const (
	VNOTEMPTY = "notempty" //无构建参数
	VBOOL     = "bool"
	VSTRLEN   = "strlen"
	VINT32    = "i32"
	VINT64    = "i64"
	VFLOAT32  = "f32"
	VFLOAT64  = "f64"
	VREGEX    = "regex"
)

默认的构建器的名称

View Source
const (
	EnvWorkfDir = "work_dir"
)

定义环境变量

View Source
const LF = '\n'

LF `\n`

Variables

View Source
var LocalLocation = time.Now().Local().Location()

LocalLocation 本地时区

Functions

func AesDecrypt

func AesDecrypt(data, key []byte) (result []byte, err error)

AesDecrypt 对data用key解密,使用PKCS5 Padding

func AesDecryptWithIV

func AesDecryptWithIV(data, key, iv []byte) (result []byte, err error)

AesDecryptWithIV 对data用key和iv解密加密,使用PKCS5 Padding

func AesEncrypt

func AesEncrypt(data, key []byte) (result []byte, err error)

AesEncrypt 对data用key加密,使用PKCS5 Padding

func AesEncryptWithIV

func AesEncryptWithIV(data, key, iv []byte) (result []byte, err error)

AesEncryptWithIV 对data用key加密,使用PKCS5 Padding

func ByteSlice2String

func ByteSlice2String(bs []byte) (str string)

ByteSlice2String convert []byte to string

func CopyNoItems added in v1.1.26

func CopyNoItems[S any, T any](src PageResult[S], dest *PageResult[T])

CopyNoItems copy all but no items

func CreateDirIfAbsent

func CreateDirIfAbsent(dir string) error

CreateDirIfAbsent 当目录不存在时创建

func DebugEnabled added in v1.1.3

func DebugEnabled() bool

DebugEnabled debug

func Debugf

func Debugf(format string, params ...interface{})

Debugf debug级别记录日志

func ErrorEnabled added in v1.1.3

func ErrorEnabled() bool

ErrorEnabled error

func Errorf

func Errorf(format string, params ...interface{})

Errorf error级别记录日志

func ExtractRefTuple

func ExtractRefTuple(obj interface{}) (val reflect.Value, ind reflect.Value, typ reflect.Type)

ExtractRefTuple 抽取反射的val:ValueOf ,ind:Indirect,typ:ind.Type

func FileBasename

func FileBasename(s string) string

FileBasename 确定不待扩展的文件名

func FillSlice

func FillSlice(num int, fillFunc func(index int))

FillSlice create slice

func Float32 added in v1.1.14

func Float32(p interface{}) (i float32, err error)

Float32 转为float32

func Float64

func Float64(p interface{}) (i float64, err error)

Float64 转为float64类型

func Fnv32Hashcode

func Fnv32Hashcode(data string) int

Fnv32Hashcode calculate abs hash code for data

func GetFieldType

func GetFieldType(structObj interface{}, fieldIndex int) reflect.Type

GetFieldType 取得structObje的指定字段的类型

func GetFirstFieldType

func GetFirstFieldType(structObj interface{}) reflect.Type

GetFirstFieldType 取得structObj的第一个字段的类型

func HasNil

func HasNil(args ...interface{}) bool

HasNil check does any args is nil

func InfoEnabled added in v1.1.3

func InfoEnabled() bool

InfoEnabled info

func Infof

func Infof(format string, params ...interface{})

Infof info级别记录日志

func Int added in v1.1.14

func Int(p interface{}) (i int, err error)

Int 转为int

func Int64

func Int64(p interface{}) (i int64, err error)

Int64 转为int64类型

func IsEmpty

func IsEmpty(strs ...string) bool

IsEmpty 是否有空字符串

func IsValNil

func IsValNil(v interface{}) bool

IsValNil 检查v的值是不是nil

func IsValidServiceState

func IsValidServiceState(oldState ServiceState, newState ServiceState) bool

IsValidServiceState 检查ServiceState的状态转移是否有效

func LoadConfig

func LoadConfig(config Configurer, addonConfig string, configDir string, pathes ...string) (err error)

LoadConfig 从configDir目录下的多个path指定的YAML配置文件中加载配置

func LoadConfigWithLoader

func LoadConfigWithLoader(loader ConfigLoader, config Configurer, addonConfig string, configDir string, pathes ...string) (err error)

LoadConfigWithLoader 使用指定的加载器加载配置

func LoadYAMLFromPath

func LoadYAMLFromPath(filename string, target interface{}) error

LoadYAMLFromPath 将YAML文件中的配置加载到到结构体target中

func LoadYAMl

func LoadYAMl(data []byte, target interface{}) error

LoadYAMl 将data中的YAML配置加载到到结构体target中

func LoggerSync

func LoggerSync()

LoggerSync sync log

func MGet

func MGet(m map[string]interface{}, key string) interface{}

MGet get value from m

func MGetInt32

func MGetInt32(m map[string]interface{}, key string) (int32, error)

MGetInt32 get int32 from m

func MGetInt64

func MGetInt64(m map[string]interface{}, key string) (int64, error)

MGetInt64 get int64 from m

func MGetString

func MGetString(m map[string]interface{}, key string) (string, error)

MGetString get string from m

func PKCS5Padding

func PKCS5Padding(ciphertext []byte, blockSize int) ([]byte, error)

PKCS5Padding pkcs5 padding

func PKCS5UnPadding

func PKCS5UnPadding(origData []byte) ([]byte, error)

PKCS5UnPadding pkcs5 unpadding

func Parse

func Parse(conf interface{}) error

Parse 解析配置

func ParseFloat32

func ParseFloat32(param string) (v float32, err error)

ParseFloat32 解析浮点数

func ParseFloat64

func ParseFloat64(param string) (v float64, err error)

ParseFloat64 解析浮点数

func ParseInput

func ParseInput(input string) (inputReader *os.File, err error)

ParseInput 解析输入的文件

func ParseInputAndOutput

func ParseInputAndOutput(input, output string) (inputReader, outWriter *os.File, err error)

ParseInputAndOutput 解析输入的文件

func ParseInt

func ParseInt(param string) (v int, err error)

ParseInt 解析整数

func ParseInt32

func ParseInt32(param string) (v int32, err error)

ParseInt32 解析整数

func ParseInt64

func ParseInt64(param string) (v int64, err error)

ParseInt64 解析整数

func ParseLocalTime

func ParseLocalTime(t string) (time.Time, error)

ParseLocalTime 解析本地时间

func ParseLocatTimeWithFormat

func ParseLocatTimeWithFormat(format, t string) (time.Time, error)

ParseLocatTimeWithFormat 解析本地时间

func PrintErrorMsgAndExit

func PrintErrorMsgAndExit(msg string, err error)

PrintErrorMsgAndExit 打印信息并退出

func ProcessFileLines added in v1.1.10

func ProcessFileLines(file string, lineFunc ProcessLineFunc)

ProcessFileLines 按行处理文件

func ProcessLines

func ProcessLines(rd io.Reader, processFunc ProcessLineFunc)

ProcessLines 按行从rd中读取数据,交由processFunc进行处理

func RandomUUID

func RandomUUID() (uuid string)

RandomUUID 生成随机的UUID

func RegValidatorNewer

func RegValidatorNewer(name string, validator ValidatorNewer)

RegValidatorNewer 根据名称注册验证器构建函数

func ServiceInit

func ServiceInit(service Service) bool

ServiceInit 初始化服务

func ServiceName

func ServiceName(service Service) string

ServiceName 取得服务的名称

func ServiceStart

func ServiceStart(service Service) bool

ServiceStart 开始服务

func ServiceStop

func ServiceStop(service Service) bool

ServiceStop 停止服务

func SetLogLevel added in v1.1.3

func SetLogLevel(level LogLevel)

SetLogLevel set the log level

func SplitTrimOmitEmpty

func SplitTrimOmitEmpty(str, sep string) []string

SplitTrimOmitEmpty 对str按sep分隔,去掉为空的项

func StackTrace

func StackTrace(all bool) string

StackTrace record the stack trace

func String2ByteSlice

func String2ByteSlice(str string) (bs []byte)

String2ByteSlice convert string to []byte

func ToSlice

func ToSlice(num int, fillFunc func(index int, dest []interface{})) []interface{}

ToSlice to slice

func TrimOmitEmpty

func TrimOmitEmpty(str []string) []string

TrimOmitEmpty 去掉为空的值

func UnixMills

func UnixMills(t time.Time) int64

UnixMills 取得毫秒

func UnixMillsTime

func UnixMillsTime(tmillis int64) time.Time

UnixMillsTime 根据毫秒取得时间

func UnmarshalUseNumber

func UnmarshalUseNumber(data []byte, v interface{}) error

UnmarshalUseNumber 使用UserNumber进行解析,避免int64被错误地转为float64

func ValidateAll

func ValidateAll(validateService ValidateService, nameAndValues ...*ValidatePair) error

ValidateAll 验证所有的规则

func WaitStop

func WaitStop() os.Signal

WaitStop 等待退出信号

func WarnEnabled added in v1.1.3

func WarnEnabled() bool

WarnEnabled warn

func Warnf

func Warnf(format string, params ...interface{})

Warnf warn级别记录日志

Types

type AppConfig

type AppConfig struct {
	*LogConfig          `yaml:"log"`
	*RuntimeConfig      `yaml:"runtime"`
	*ValidateRuleConfig `yaml:"validates"`
}

AppConfig 基础的应用配置

func (*AppConfig) GetLogConfig

func (p *AppConfig) GetLogConfig() *LogConfig

GetLogConfig impls LogConfiger

func (*AppConfig) GetValidateRuleConfig

func (p *AppConfig) GetValidateRuleConfig() *ValidateRuleConfig

GetValidateRuleConfig implements ValidateConfiguer

func (*AppConfig) Parse

func (p *AppConfig) Parse() error

Parse 解析基础的应用配置

type BaseService

type BaseService struct {
	SName string //服务的名称
	Order int
	// contains filtered or unexported fields
}

BaseService 提供基本的Service接口实现

func (*BaseService) GetStartOrder

func (p *BaseService) GetStartOrder() int

GetStartOrder 启动服务

func (*BaseService) GetStopOrder

func (p *BaseService) GetStopOrder() int

GetStopOrder 停止服务

func (*BaseService) Init

func (p *BaseService) Init() error

Init 初始化

func (*BaseService) Name

func (p *BaseService) Name() string

Name 服务名称

func (*BaseService) Start

func (p *BaseService) Start() bool

Start 启动服务

func (*BaseService) State

func (p *BaseService) State() ServiceState

State 取得服务的状态

func (*BaseService) Stop

func (p *BaseService) Stop() bool

Stop 停止服务

type BoolValidator

type BoolValidator struct {
}

BoolValidator bool验证

func (*BoolValidator) Validate

func (p *BoolValidator) Validate(param string) bool

Validate 验证bool值

type ConfigFileLoader

type ConfigFileLoader struct {
}

ConfigFileLoader 从本地文件中加载配置

func (*ConfigFileLoader) Exist

func (p *ConfigFileLoader) Exist(configPath string) (exist bool, err error)

Exist impls ConfigLoader.Exist

func (*ConfigFileLoader) Load

func (p *ConfigFileLoader) Load(configPath string) (content []byte, err error)

Load impls ConfigLoader.Load

type ConfigLoader

type ConfigLoader interface {
	Load(configPath string) (content []byte, err error)

	Exist(configPath string) (exist bool, err error)
}

ConfigLoader 配置内容加载器

var (
	//FileLoader 默认加载
	FileLoader ConfigLoader = &ConfigFileLoader{}
)

type Configurer

type Configurer interface {
	//解析配置
	Parse() error
}

Configurer 配置器

type CopyOnWriteMap

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

CopyOnWriteMap copy on write map

func NewCopyOnWriteMap

func NewCopyOnWriteMap() *CopyOnWriteMap

NewCopyOnWriteMap 创建CopyOnWriteMap

func (*CopyOnWriteMap) Delete

func (p *CopyOnWriteMap) Delete(key interface{})

Delete 删除key

func (*CopyOnWriteMap) Get

func (p *CopyOnWriteMap) Get(key interface{}) interface{}

Get 取得key对应的值

func (*CopyOnWriteMap) Put

func (p *CopyOnWriteMap) Put(key interface{}, value interface{})

Put key及对应的value,如果key已经存在,则进行替换

func (*CopyOnWriteMap) PutIfAbsent

func (p *CopyOnWriteMap) PutIfAbsent(key interface{}, value interface{}) error

PutIfAbsent put key及对应的value,如果key已经存在,不进行替换,并返回错误

type CopyOnWriteSlice

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

CopyOnWriteSlice copy on write slice

func NewCopyOnWriteSlice

func NewCopyOnWriteSlice() *CopyOnWriteSlice

NewCopyOnWriteSlice 创建CopyOnWriteSlice

func (*CopyOnWriteSlice) Add

func (p *CopyOnWriteSlice) Add(value interface{}) error

Add 添加

func (*CopyOnWriteSlice) Delete

func (p *CopyOnWriteSlice) Delete(value interface{}) error

Delete 删除value

func (*CopyOnWriteSlice) Get

func (p *CopyOnWriteSlice) Get() []interface{}

Get 取得Slice

type CurrentMap

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

CurrentMap A "thread" safe map of type interface{}:interface{},auto gen from concurrent_map_template.go

func NewCurrentMap

func NewCurrentMap() *CurrentMap

NewCurrentMap Create a new concurrent map with 32 shards

func NewCurrentMapWithShard

func NewCurrentMapWithShard(shardCount uint) *CurrentMap

NewCurrentMapWithShard Creates a new concurrent map.

func (*CurrentMap) Count

func (m *CurrentMap) Count() int

Count Returns the number of elements within the map.

func (*CurrentMap) Get

func (m *CurrentMap) Get(key interface{}) (interface{}, bool)

Get Retrieves an element from map under given key.

func (*CurrentMap) Has

func (m *CurrentMap) Has(key interface{}) bool

Has Looks up an item under specified key

func (*CurrentMap) IsEmpty

func (m *CurrentMap) IsEmpty() bool

IsEmpty Checks if map is empty.

func (CurrentMap) Items

func (m CurrentMap) Items() map[interface{}]interface{}

Items Returns all items as map[interface{}]interface{}

func (CurrentMap) Iter

func (m CurrentMap) Iter() <-chan CurrentMapTuple

Iter Returns an iterator which could be used in a for range loop.

func (CurrentMap) IterBuffered

func (m CurrentMap) IterBuffered() <-chan CurrentMapTuple

IterBuffered Returns a buffered iterator which could be used in a for range loop.

func (*CurrentMap) Remove

func (m *CurrentMap) Remove(key interface{})

Remove an element from the map.

func (*CurrentMap) Set

func (m *CurrentMap) Set(key interface{}, value interface{})

Set the given value under the specified key.

func (*CurrentMap) SetIfAbsent

func (m *CurrentMap) SetIfAbsent(key interface{}, value interface{}) (success bool, preVal interface{})

SetIfAbsent the given value under the specified key if no value was associated with it.

type CurrentMapTuple

type CurrentMapTuple struct {
	Key interface{}
	Val interface{}
}

CurrentMapTuple Used by the Iter & IterBuffered functions to wrap two variables together over a channel,

type Float32Validator

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

Float32Validator 32位浮点数验证

func (*Float32Validator) Validate

func (p *Float32Validator) Validate(param string) bool

Validate 验证浮点数值

type Float64Validator

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

Float64Validator 64位浮点数验证

func (*Float64Validator) Validate

func (p *Float64Validator) Validate(param string) bool

Validate 验证浮点数值

type Initable

type Initable interface {
	// Init 执行初始化操作,如果初始化失败,返回错误的原因
	Init() error
}

Initable 表示需要进行初始化

type Int32Slice

type Int32Slice []int32

Int32Slice int32 slice

func (Int32Slice) Len added in v1.1.1

func (p Int32Slice) Len() int

func (Int32Slice) Less added in v1.1.1

func (p Int32Slice) Less(i, j int) bool

func (Int32Slice) Swap added in v1.1.1

func (p Int32Slice) Swap(i, j int)

func (Int32Slice) ToInterface

func (p Int32Slice) ToInterface() []interface{}

ToInterface 转为interface slice

type Int32Validator

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

Int32Validator 32位整数验证

func (*Int32Validator) Validate

func (p *Int32Validator) Validate(param string) bool

Validate 验证整型值

type Int64Slice

type Int64Slice []int64

Int64Slice int64 slice

func (Int64Slice) Len added in v1.1.1

func (p Int64Slice) Len() int

func (Int64Slice) Less added in v1.1.1

func (p Int64Slice) Less(i, j int) bool

func (Int64Slice) Swap added in v1.1.1

func (p Int64Slice) Swap(i, j int)

func (Int64Slice) ToInterface

func (p Int64Slice) ToInterface() []interface{}

ToInterface 转为interface slice

type Int64Validator

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

Int64Validator 64位整数验证

func (*Int64Validator) Validate

func (p *Int64Validator) Validate(param string) bool

Validate 验证整型值

type IntSlice

type IntSlice []int

IntSlice int slice

func (IntSlice) Len added in v1.1.1

func (p IntSlice) Len() int

func (IntSlice) Less added in v1.1.1

func (p IntSlice) Less(i, j int) bool

func (IntSlice) Swap added in v1.1.1

func (p IntSlice) Swap(i, j int)

func (IntSlice) ToInterface

func (p IntSlice) ToInterface() []interface{}

ToInterface 转为interface slice

type LinkedMap

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

LinkedMap implements linked map

func NewLinkedMap

func NewLinkedMap() *LinkedMap

NewLinkedMap create linked map

func (*LinkedMap) Entries

func (p *LinkedMap) Entries() []*MapEntry

Entries return entry slice

func (*LinkedMap) Get

func (p *LinkedMap) Get(key interface{}) (val interface{}, ok bool)

Get value with key

func (*LinkedMap) Len

func (p *LinkedMap) Len() int

Len return the length of the map

func (*LinkedMap) Put

func (p *LinkedMap) Put(key, value interface{})

Put put value with key

func (*LinkedMap) Remove

func (p *LinkedMap) Remove(key interface{}) (preVal interface{})

Remove value with key

type LogConfig

type LogConfig struct {
	Env        string `yaml:"env"`
	FileName   string `yaml:"file_name"`
	MaxSize    int    `yaml:"max_size"`
	MaxBackups int    `yaml:"max_backups"`
	MaxAge     int    `yaml:"max_age"`
	NoCaller   bool   `yaml:"no_caller"`
	Level      string `yaml:"level"`
}

LogConfig 日志配置

func (*LogConfig) Parse

func (p *LogConfig) Parse() error

Parse 解析日志配置

type LogConfiger

type LogConfiger interface {
	GetLogConfig() *LogConfig
}

LogConfiger the log configer

type LogLevel added in v1.1.3

type LogLevel string

LogLevel log level

const (
	Debug LogLevel = "debug"
	Info  LogLevel = "info"
	Warn  LogLevel = "warn"
	Error LogLevel = "error"
)

log levels

type Logger

type Logger interface {
	Debugf(format string, params ...interface{})
	DebugEnabled() bool
	Infof(format string, params ...interface{})
	InfoEnabled() bool
	Warnf(format string, params ...interface{})
	WarnEnabled() bool
	Errorf(format string, params ...interface{})
	ErrorEnabled() bool
	SetLevel(level LogLevel)
	Sync()
}

Logger 日志记录接口

type MapEntry

type MapEntry struct {
	Key   interface{}
	Value interface{}
}

MapEntry define map entry with key and value

type NotEmptyValidator

type NotEmptyValidator struct {
}

NotEmptyValidator 非空

func (*NotEmptyValidator) Validate

func (p *NotEmptyValidator) Validate(param string) bool

Validate 验证字符串是否为空

type PageParam

type PageParam struct {
	//页数,从1开始
	Page int `json:"page"`
	//每页的条数,>0
	PageSize int `json:"page_size"`
	//游标
	Cursor int64 `json:"cursor"`
}

PageParam 分页参数

func (*PageParam) EndIndex

func (p *PageParam) EndIndex() int

EndIndex 返回从0开始的截止索引

func (*PageParam) Limit

func (p *PageParam) Limit(maxPage, maxPageSize int)

Limit 根据maxPage和maxPageSize限制Page和PageSize

func (*PageParam) StartIndex

func (p *PageParam) StartIndex() int

StartIndex 返回从0开始的起始索引

type PageResult

type PageResult[T any] struct {
	PageParam
	Total     int64 `json:"total"`
	TotalPage int64 `json:"totalPage"`
	Items     []T   `json:"items"`
}

PageResult 分页结果

func (*PageResult[T]) CalTotalPage

func (p *PageResult[T]) CalTotalPage()

CalTotalPage 计算总页数

func (*PageResult[T]) SetData

func (p *PageResult[T]) SetData(items []T)

SetData implements ResultSet.SetData

func (*PageResult[T]) SetTotal

func (p *PageResult[T]) SetTotal(total int64)

SetTotal set total

type ProcessLineFunc

type ProcessLineFunc func(data string, lineNum int, readErr error) (stop bool)

ProcessLineFunc 行处理函数

type Query

type Query struct {
	PageParam
	//ID
	ID int64 `json:"id"`
}

Query 基本的查询参数

type RegExValidator

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

RegExValidator 正则表达式验证

func (*RegExValidator) Validate

func (p *RegExValidator) Validate(param string) bool

Validate 正则表达式验证

type RuleConfig

type RuleConfig struct {
	Name       string
	Desc       string              //规则描述
	Validators []map[string]string //验证器列表,必须要有name
}

RuleConfig 验证规则配置

type RuleValidateService

type RuleValidateService struct {
	BaseService
	Config ValidateConfigurer `inject:"_"`
	// contains filtered or unexported fields
}

RuleValidateService 根据规则进行的验证服务

func (*RuleValidateService) Init

func (p *RuleValidateService) Init() error

Init implements Initable

func (*RuleValidateService) Validate

func (p *RuleValidateService) Validate(ruleName string, s string) error

Validate 验证

type RuntimeConfig

type RuntimeConfig struct {
	Maxprocs int //最大的PROCS个数
}

RuntimeConfig 运行期配置

func (*RuntimeConfig) Parse

func (p *RuntimeConfig) Parse() error

Parse 解析运行期配置

type Service

type Service interface {
	Initable
	// Name 取得服务名称
	Name() string
	// Start 启动服务
	Start() bool
	// 启动的次序
	GetStartOrder() int
	// Stop 停止服务
	Stop() bool
	// 停止的次序
	GetStopOrder() int
	// State 服务的状态
	State() ServiceState
	// contains filtered or unexported methods
}

Service 统一的服务接口

type ServiceState

type ServiceState uint32

ServiceState 表示服务的状态

const (
	// NEW 新建“
	NEW ServiceState = iota
	// INITED 初始化完毕
	INITED
	// STARTING 正在启动
	STARTING
	// RUNNING 正在运行
	RUNNING
	// STOPPING 正在停止
	STOPPING
	// TERMINATED 已经停止
	TERMINATED
	// FAILED 失败
	FAILED
)

func (ServiceState) String

func (p ServiceState) String() string

type Services

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

Services 一组Service的集合

func NewServices

func NewServices(services []Service, start bool) *Services

NewServices 构建新的Service集合

func (*Services) Init

func (p *Services) Init() bool

Init 初始化服务集合

func (*Services) Start

func (p *Services) Start() bool

Start 启动服务

func (*Services) Stop

func (p *Services) Stop() bool

Stop 停止服务

type Shutdownhook

type Shutdownhook struct {
	sync.Mutex //同步锁
	// contains filtered or unexported fields
}

Shutdownhook 停止hook

func NewShutdownhook

func NewShutdownhook(sig ...os.Signal) *Shutdownhook

NewShutdownhook 创建一个Shutdownhook,sig是要监听的信号,默认会监听syscall.SIGINT,syscall.SIGTERM

func (*Shutdownhook) AddHook

func (p *Shutdownhook) AddHook(hookFunc func())

AddHook 增加一个Hook函数

func (*Shutdownhook) IsOSStop

func (p *Shutdownhook) IsOSStop() bool

IsOSStop 是否OS触发的停止

func (*Shutdownhook) Stop

func (p *Shutdownhook) Stop()

Stop the shutdownhook

func (*Shutdownhook) WaitShutdown

func (p *Shutdownhook) WaitShutdown()

WaitShutdown 等待进程退出的信号,当收到进程退出的信号后,依次执行注册的hook函数

type Status

type Status int8

Status 定义状态

const (
	// DISABLE 禁用
	DISABLE Status = 0
	// ENABLE 有效
	ENABLE Status = 1
)

func (Status) IsValid

func (p Status) IsValid() bool

IsValid 判断状态是否是有效的

func (Status) Value

func (p Status) Value() int8

Value 状态的值

type StdLogger

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

StdLogger 使用标准库封装的logger

func NewStdLogger

func NewStdLogger() *StdLogger

NewStdLogger new info level logger

func (*StdLogger) DebugEnabled added in v1.1.3

func (l *StdLogger) DebugEnabled() bool

DebugEnabled is debug enbale

func (*StdLogger) Debugf

func (l *StdLogger) Debugf(format string, params ...interface{})

Debugf debug

func (*StdLogger) ErrorEnabled added in v1.1.3

func (l *StdLogger) ErrorEnabled() bool

ErrorEnabled error

func (*StdLogger) Errorf

func (l *StdLogger) Errorf(format string, params ...interface{})

Errorf error

func (*StdLogger) InfoEnabled added in v1.1.3

func (l *StdLogger) InfoEnabled() bool

InfoEnabled is info enable

func (*StdLogger) Infof

func (l *StdLogger) Infof(format string, params ...interface{})

Infof info

func (*StdLogger) SetLevel added in v1.1.3

func (l *StdLogger) SetLevel(level LogLevel)

SetLevel set the log level

func (*StdLogger) Sync

func (l *StdLogger) Sync()

Sync sync

func (*StdLogger) WarnEnabled added in v1.1.3

func (l *StdLogger) WarnEnabled() bool

WarnEnabled is warn enabled

func (*StdLogger) Warnf

func (l *StdLogger) Warnf(format string, params ...interface{})

Warnf warn

type StrValidator

type StrValidator interface {
	//Vlidate 验证字符串参数是否符合规则
	Validate(param string) bool
}

StrValidator 字符串验证器

func NewBoolValidator

func NewBoolValidator(conf map[string]string) StrValidator

NewBoolValidator 创建bool验证器

func NewFloat32Validator

func NewFloat32Validator(conf map[string]string) StrValidator

NewFloat32Validator 创建float32验证,conf["min"],最小值;conf["max"],最大值

func NewFloat64Validator

func NewFloat64Validator(conf map[string]string) StrValidator

NewFloat64Validator 创建float64验证,conf["min"],最小值;conf["max"],最大值

func NewInt32Validator

func NewInt32Validator(conf map[string]string) StrValidator

NewInt32Validator 创建int32验证,conf["min"],最小值;conf["max"],最大值

func NewInt64Validator

func NewInt64Validator(conf map[string]string) StrValidator

NewInt64Validator 创建int64验证,conf["min"],最小值;conf["max"],最大值

func NewNotEmptyValidator

func NewNotEmptyValidator(conf map[string]string) StrValidator

NewNotEmptyValidator 创建非空验证器

func NewRegexValidator

func NewRegexValidator(conf map[string]string) StrValidator

NewRegexValidator 创建正则表达式验证,conf["pattern"] 正则表达式

func NewStrLenValidator

func NewStrLenValidator(conf map[string]string) StrValidator

NewStrLenValidator 创建字符串长度验证,conf["min"],最小值;conf["max"],最大值

func NewValidatorByConf

func NewValidatorByConf(conf map[string]string) StrValidator

NewValidatorByConf 根据配置conf["name"]及其对应的参数构建验证器

type StringLenValidator

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

StringLenValidator 字符串长度验证

func (*StringLenValidator) Validate

func (p *StringLenValidator) Validate(param string) bool

Validate 验证字符串的长度

type StringSlice

type StringSlice []string

StringSlice string slice

func (StringSlice) ToFloat32

func (p StringSlice) ToFloat32() ([]float32, error)

ToFloat32 转为[]float32

func (StringSlice) ToFloat64

func (p StringSlice) ToFloat64() ([]float64, error)

ToFloat64 转为[]floa64t

func (StringSlice) ToInt

func (p StringSlice) ToInt() ([]int, error)

ToInt 转为[]int

func (StringSlice) ToInt16 added in v1.1.6

func (p StringSlice) ToInt16() ([]int16, error)

ToInt16 转为[]int16

func (StringSlice) ToInt32

func (p StringSlice) ToInt32() ([]int32, error)

ToInt32 转为[]int32

func (StringSlice) ToInt64

func (p StringSlice) ToInt64() ([]int64, error)

ToInt64 转为[]int64

func (StringSlice) ToInt8 added in v1.1.6

func (p StringSlice) ToInt8() ([]int8, error)

ToInt8 转为[]int8

func (StringSlice) ToInterface

func (p StringSlice) ToInterface() []interface{}

ToInterface 转为interface slice

func (StringSlice) ToNumber

func (p StringSlice) ToNumber(typ interface{}) (interface{}, error)

ToNumber 转为数字slice

func (StringSlice) ToUint added in v1.1.18

func (p StringSlice) ToUint() ([]uint, error)

ToUint 转为[]uint

func (StringSlice) ToUint16 added in v1.1.18

func (p StringSlice) ToUint16() ([]uint16, error)

ToUint16 转为[]uint16

func (StringSlice) ToUint32 added in v1.1.18

func (p StringSlice) ToUint32() ([]uint32, error)

ToUint32 转为[]uint32

func (StringSlice) ToUint64 added in v1.1.18

func (p StringSlice) ToUint64() ([]uint64, error)

ToUint64 转为[]uint64

func (StringSlice) ToUint8 added in v1.1.18

func (p StringSlice) ToUint8() ([]uint8, error)

ToUint8 转为[]uint8

type StructCopier

type StructCopier func(from interface{}, to interface{}) (err error)

StructCopier struct结构拷贝

func NewStructCopier

func NewStructCopier(from interface{}, to interface{}) (copier StructCopier, err error)

NewStructCopier 拷贝

type ValidateConfigurer

type ValidateConfigurer interface {
	GetValidateRuleConfig() *ValidateRuleConfig
}

ValidateConfigurer validateConfig

type ValidateError

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

ValidateError error

func NewValidateError

func NewValidateError(msg string) *ValidateError

NewValidateError new

func (*ValidateError) Error

func (p *ValidateError) Error() string

func (*ValidateError) Human

func (p *ValidateError) Human() bool

Human impls HumanError.Human

type ValidatePair

type ValidatePair struct {
	Name  string
	Value string
	Msg   string
}

ValidatePair 定义验证规则名称其需要验证的值

func NewValidatePair

func NewValidatePair(name, value string) *ValidatePair

NewValidatePair create ValidatePair

func NewValidatePairMsg

func NewValidatePairMsg(name, value, msg string) *ValidatePair

NewValidatePairMsg create ValidatePair with msg

type ValidateRule

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

ValidateRule 定义验证规则

type ValidateRuleConfig

type ValidateRuleConfig struct {
	Rules []RuleConfig
	SName string //服务的名称
	// contains filtered or unexported fields
}

ValidateRuleConfig 验证规则配置

func (*ValidateRuleConfig) NewService

func (p *ValidateRuleConfig) NewService() Service

NewService 根据配置解析的结果创建验证服务

func (*ValidateRuleConfig) Parse

func (p *ValidateRuleConfig) Parse() error

Parse 解析验证的配置

type ValidateService

type ValidateService interface {
	Service
	//Validate 使用name指定验证规则,对value进行验证,验证通过返回nil,否则返回错误原因
	Validate(name string, value string) error
}

ValidateService 验证服务

type ValidatorNewer

type ValidatorNewer func(conf map[string]string) StrValidator

ValidatorNewer 创建验证器的函数类型

type ZapLogger

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

ZapLogger 使用zap封装的logger

func NewZapLogger

func NewZapLogger(logConfig *LogConfig) *ZapLogger

NewZapLogger new zap logger

func (*ZapLogger) DebugEnabled added in v1.1.3

func (l *ZapLogger) DebugEnabled() bool

DebugEnabled is debug enbale

func (*ZapLogger) Debugf

func (l *ZapLogger) Debugf(format string, params ...interface{})

Debugf debug

func (*ZapLogger) ErrorEnabled added in v1.1.3

func (l *ZapLogger) ErrorEnabled() bool

ErrorEnabled is info enbale

func (*ZapLogger) Errorf

func (l *ZapLogger) Errorf(format string, params ...interface{})

Errorf error

func (*ZapLogger) InfoEnabled added in v1.1.3

func (l *ZapLogger) InfoEnabled() bool

InfoEnabled is info enbale

func (*ZapLogger) Infof

func (l *ZapLogger) Infof(format string, params ...interface{})

Infof info

func (*ZapLogger) SetLevel added in v1.1.3

func (l *ZapLogger) SetLevel(level LogLevel)

SetLevel set the log level

func (*ZapLogger) Sync

func (l *ZapLogger) Sync()

Sync impls Logger.Sync

func (*ZapLogger) WarnEnabled added in v1.1.3

func (l *ZapLogger) WarnEnabled() bool

WarnEnabled is info enbale

func (*ZapLogger) Warnf

func (l *ZapLogger) Warnf(format string, params ...interface{})

Warnf warn

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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