common

package
v0.0.0-...-8d9db00 Latest Latest
Warning

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

Go to latest
Published: Feb 26, 2017 License: MIT Imports: 18 Imported by: 0

Documentation

Index

Constants

View Source
const (
	//ErrCodedParams 请求参数错误
	ErrCodedParams = 400
	//ErrCodeNotFound 没有发现
	ErrCodeNotFound = 404
	//ErrCodeInternal 内部错误
	ErrCodeInternal = 500
)

Variables

This section is empty.

Functions

func CheckError

func CheckError(err error)

CheckError 打印普通错误

func CheckFatal

func CheckFatal(err error)

CheckFatal 打印失败类型错误,并因此停止程序运行

func ConfigRuntime

func ConfigRuntime()

ConfigRuntime 多核运行

func DeepCopy

func DeepCopy(dst, src interface{}) error

复制对象

func EncryptMAC

func EncryptMAC(s, key string) []byte

EncryptMAC 用hmac加密字符串。每次加密后的密文长度都是32位。可用于字符串完整性校验

func EncryptMD5

func EncryptMD5(s string) []byte

EncryptMD5 用md5加密字符串。每次加密后的密文长度都是16位。可用于字符串完整性校验

func ExecCommand

func ExecCommand(commandName string, arg ...string) ([]string, error)

ExecCommand 执行系统命令

func InitConfig

func InitConfig(appName, cfgFile string)

InitConfig 读取配置文件,如果有配置文件(cfgFile != ""),读取配置文件。 否则,在/etc/[appName]/、$HOME/.[appName]/、./config/目录下需找文件名为config的配置文件。

func JSONObjectConvert

func JSONObjectConvert(obj1 interface{}, obj2 interface{}) error

JSONObjectConvert 将一个对象转换成序列化后的另一个对象

func PrettyJSON

func PrettyJSON(b []byte) ([]byte, error)

PrettyJSON 打印缩进后的json内容

func PrettyObject

func PrettyObject(obj interface{}) []byte

func RandInt64

func RandInt64(min, max int64) int64

RandInt64 生成随机数字

func RandString

func RandString(length int) []byte

RandString 生成随机字符串

func ReadConfigFromKey

func ReadConfigFromKey(configKey string, config interface{})

ReadConfigFromKey 从读取的配置中寻找符合configKey的配置,并赋值到配置对象(config)定义的变量中。 如果config有环境变量定义,那么以环境变量设置为准

func ReadEnv

func ReadEnv(obj interface{}) error

ReadEnv 读取struct内env的标签内容,转为读取环境变量

func ReadFileData

func ReadFileData(path string) ([]byte, error)

func ReadJSON

func ReadJSON(obj interface{}, data []byte) error

ReadJSON 将json格式的byte内容转换成对象

Types

type Error

type Error struct {
	Code    int    `json:"status"`
	Message string `json:"error"`
}

Error 自定义错误

func NewError

func NewError(code int, message string) *Error

NewError 生成新的自定义错误对象

func (*Error) Error

func (e *Error) Error() string

Error 继承错误输出接口

type Timer

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

func NewTimer

func NewTimer() *Timer

func (*Timer) Start

func (t *Timer) Start()

func (*Timer) Stop

func (t *Timer) Stop()

Jump to

Keyboard shortcuts

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