tyr

package module
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Mar 11, 2019 License: MIT Imports: 12 Imported by: 0

README

Documentation

Index

Constants

View Source
const (
	TimeFmtLong    = `2006-01-02 15:04:05` // yyyy-MM-dd hh:mm:ss
	TimeFmtNumeric = `20060102150405`      // yyyyMMddhhmmss

	DateFmtLong    = `2006-01-02` // yyyy-MM-dd
	DateFmtNumeric = `20060102`   // yyyyMMdd
)

Time fmt

View Source
const (
	ErrOk               = 0
	ErrNotFound         = 1001 // ErrNotFound 404 route not found
	ErrException        = 1002 // ErrException 500
	ErrBadRequest       = 1003 // ErrBadRequest 400 route params error
	ErrMethodNotAllowed = 1004 // ErrMethodNotAllowed 405
	ErrParamsError      = 1005 // ErrParamsError 415
	ErrUnAuthorized     = 1006 // ErrUnAuthorized 401
	ErrDataNotFound     = 1007 // ErrDataNotFound 404
	ErrNotAllowed       = 1008 // ErrNotAllowed 405
	ErrDataExists       = 1009 // ErrDataExists 400
	ErrDataValidate     = 1010 // ErrDataValidate 403

	VarUserAuthorization    = `access_token`  // oauth token
	HTTPHeaderAuthorization = `Authorization` // HTTP header Authorization
	HTTPHeaderToken         = `X-Token`       // HTTP header Authorization X-Token
)

Error code & constant

View Source
const (
	LibName    = `tyr`   // LibName toolkit name Go micro service
	LibVersion = `0.4.0` // LibVersion toolkit version
)

Library constant

Variables

This section is empty.

Functions

func CheckCharYesNo

func CheckCharYesNo(s string) bool

CheckCharYesNo check Y or N

func CheckIntRange

func CheckIntRange(n, min, max int) bool

CheckIntRange 检测整数范围

func CheckStringLength

func CheckStringLength(s string, min, max int) bool

CheckStringLength 检测字符串是否符合指定长度范围

func CloseDefaultLogger

func CloseDefaultLogger() error

CloseDefaultLogger close

func GetAesCryptoKey

func GetAesCryptoKey() string

GetAesCryptoKey get current key

func IsDate

func IsDate(s string) bool

IsDate 是否为有效日期

func IsHexString

func IsHexString(s string) bool

IsHexString 字符串是否 16 进制解码字符串

func IsTime

func IsTime(s string) bool

IsTime 是否时间格式字符串

func IsWeekEnd

func IsWeekEnd(d time.Weekday) bool

IsWeekEnd 日期是否周末

func LogDebug

func LogDebug(v ...interface{})

LogDebug log debug

func LogInfo

func LogInfo(v ...interface{})

LogInfo log info

func MD5

func MD5(data string) string

MD5 hash string

func SHA1

func SHA1(data string) string

SHA1 hash string

func SHA256

func SHA256(data string) string

SHA256 hash string

func SHA512

func SHA512(data []byte) ([]byte, error)

SHA512 hash

func SetAesCryptoKey

func SetAesCryptoKey(password string)

SetAesCryptoKey set key, key length:16, 24, 32 bytes to AES-128, AES-192, AES-256

func Str2Date

func Str2Date(s string) (t time.Time, err error)

Str2Date 字符串转日期

func Str2Time

func Str2Time(s string) (t time.Time, err error)

Str2Time 字符串转时间

func StrFmtTime

func StrFmtTime(s, fmt string) (t time.Time, err error)

StrFmtTime 时间转字符串

func StrLen

func StrLen(s string) int

StrLen utf8 string length

func Time2Str

func Time2Str(t time.Time) string

Time2Str 时间转字符串

func TimeFmtStr

func TimeFmtStr(t time.Time, fmt string) string

TimeFmtStr 时间转字符串

Types

type AesCrypto

type AesCrypto struct {
	Key []byte
}

AesCrypto define

func NewAesCrypto

func NewAesCrypto() *AesCrypto

NewAesCrypto new AesCrypto

func (*AesCrypto) Decrypt

func (a *AesCrypto) Decrypt(crypted []byte) ([]byte, error)

Decrypt decrypt data

func (*AesCrypto) Encrypt

func (a *AesCrypto) Encrypt(origData []byte) ([]byte, error)

Encrypt encrypt data

func (*AesCrypto) SetKey

func (a *AesCrypto) SetKey(key string)

SetKey set key

type Logger

type Logger struct {
	FP  *os.File
	Log *log.Logger
}

Logger logger

func NewDefaultLogger

func NewDefaultLogger(path string) (*Logger, error)

NewDefaultLogger defult logger

func NewLogger

func NewLogger(path string) (logger *Logger, err error)

NewLogger new

func ReopenDefaultLogger

func ReopenDefaultLogger(path string) (*Logger, error)

ReopenDefaultLogger re open default logger

func (Logger) Close

func (logger Logger) Close() error

Close close

func (Logger) Debug

func (logger Logger) Debug(v ...interface{})

Debug log debug

func (Logger) Info

func (logger Logger) Info(v ...interface{})

Info log info

type ReplyData

type ReplyData struct {
	Status    int               `json:"status" xml:"status"`                     // Status code
	Message   string            `json:"message" xml:"message"`                   // Message description
	Errs      map[string]string `json:"errors,omitempty" xml:"errors,omitempty"` // Errs errors
	PageCount int               `json:"pageCount,omitempty"`
	Total     int               `json:"total,omitempty" xml:"total,omitempty"` // Total data total
	List      interface{}       `json:"rows,omitempty" xml:"rows,omitempty"`   // List data list
	Data      interface{}       `json:"data,omitempty" xml:"data,omitempty"`   // Data data attribute
}

ReplyData define API output data

func ErrReplyData

func ErrReplyData(status int, message string) *ReplyData

ErrReplyData creates and return ReplyData with error and message

func ErrorsReplyData

func ErrorsReplyData(status int, errors map[string]string) *ReplyData

ErrorsReplyData creates and return ReplyData with errors

func NewReplyData

func NewReplyData(status int) *ReplyData

NewReplyData creates and return ReplyData with status and message

func OkReplyData

func OkReplyData() *ReplyData

OkReplyData creates and return ReplyData with ok

func RowReplyData

func RowReplyData(row interface{}) *ReplyData

RowReplyData creates and return ReplyData with attr row

func RowsReplyData

func RowsReplyData(total, pageCount int, rows interface{}) *ReplyData

RowsReplyData creates and return ReplyData with total and list

Directories

Path Synopsis
Package httprouter is a trie based high performance HTTP request router.
Package httprouter is a trie based high performance HTTP request router.

Jump to

Keyboard shortcuts

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