utils

package
v0.0.0-...-0747d37 Latest Latest
Warning

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

Go to latest
Published: Apr 16, 2018 License: GPL-3.0 Imports: 31 Imported by: 9

Documentation

Index

Constants

View Source
const (
	// Standard length of uniuri string to achive ~95 bits of entropy.
	StdLen = 16
	// Length of uniurl string to achive ~119 bits of entropy, closest
	// to what can be losslessly converted to UUIDv4 (122 bits).
	UUIDLen = 20
)
View Source
const (
	//成功
	SUCCESS_CODE = 200
	//错误
	ERROR_CODE = 400
	//授权失败
	AUTH_FAIL = 401
	//登陆无效
	LOGIN_INVALID_CODE = 402
	//失败
	FAIL_DATA = 403
	//数据为空
	NULL_DATA = 404
	//不是会员
	NOT_MEMBER = 500
	//会员续费通知
	MEMBER_RENEW = 501

	AUTH_WECHAT_FAIL = 5401
)
View Source
const (
	DistrictIdBits = uint(2) //区域 所占用位置
	NodeIdBits     = uint(4) //节点 所占位置

	DistrictIdShift = sequenceBits + NodeIdBits
)
View Source
const PAGE_SIZE = 10

Variables

View Source
var StdChars = []byte("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789")

Standard characters allowed in uniuri string.

Functions

func ActionLogs

func ActionLogs(c echo.Context, t string, accountId int64) map[string]interface{}

func ActionLogsMap

func ActionLogsMap(c echo.Context, t, remarks string, accountId int64) map[string]interface{}

func Alert

func Alert(c echo.Context, tip string) error

func AuthFail

func AuthFail(c echo.Context, msg string) error

func AuthFailNull

func AuthFailNull(c echo.Context) error

func AuthWechatFailNull

func AuthWechatFailNull(c echo.Context) error

func CheckEmail

func CheckEmail(value interface{}) bool

检查email

func CheckFloat64Range

func CheckFloat64Range(value interface{}, min, max float64) bool

检查float数据的区间(开区间)

func CheckIPv4

func CheckIPv4(value interface{}) bool

合法的IPV4

func CheckIntRange

func CheckIntRange(value interface{}, min, max int) bool

检查int数据的区间(开区间)

func CheckLen

func CheckLen(value interface{}, length int) bool

检查传入的值的长度,仅支持string、slice或者map 计算String的时候,以正则实现,中文字符算长度1

func CheckMax

func CheckMax(value interface{}, max float64) bool

检查传入的数值的上限,基本上支持各种类型

func CheckMaxSize

func CheckMaxSize(value interface{}, maxSize int) bool

检查传入的值的长度,仅支持string、slice或者map 计算String的时候,以正则实现,中文字符算长度1

func CheckMin

func CheckMin(value interface{}, min float64) bool

检查传入的数值的下限,基本上支持各种类型

func CheckMinSize

func CheckMinSize(value interface{}, minSize int) bool

检查传入的值的长度,仅支持string、slice或者map 计算String的时候,以正则实现,中文字符算长度1

func CheckMobile

func CheckMobile(value interface{}) bool

检查手机

func CheckRealNumber

func CheckRealNumber(value interface{}) bool

检查传入值是否是实数(包括表示实数的字符串)

func CheckRegexp

func CheckRegexp(value interface{}, rex string) bool

根据正则检查字符串,如果传入的不是string类型,则使用Sprintf处理成字符串再校验。

func CheckType

func CheckType(value interface{}, expectType string) bool

检查数据类型(基于字符串)

func Cmd

func Cmd(c Command) error

func CreateFile

func CreateFile(path string) (*os.File, error)

func CreateQrCode

func CreateQrCode(url string) (string, error)

func CreateQrCodeBytes

func CreateQrCodeBytes(url string) (bytes.Buffer, error)

func CurrentDate

func CurrentDate() string

func CurrentDateByPlace

func CurrentDateByPlace(place string) string

func CurrentDirectory

func CurrentDirectory() string

当前目录

func CurrentTime

func CurrentTime() string

func Error

func Error(c echo.Context, msg string, data interface{}) error

func ErrorNull

func ErrorNull(c echo.Context, msg string) error

func FormatTime

func FormatTime(t time.Time) string

func GetIp

func GetIp() string

func GetMac

func GetMac() string

func GetPageIndex

func GetPageIndex(pi string) int

func GetPageSize

func GetPageSize(ps string) int

func ID

func ID() int64

func IsArray

func IsArray(value interface{}) bool

传入参数是否一个数组或者切片

func IsUrl

func IsUrl(url string) bool

func IsValidBoolean

func IsValidBoolean(s string) bool

检查字符串是否代表一个合法的bool值 注意返回值仅表示是不是布尔值,并不表示布尔值本身的含义

func IsValidDate

func IsValidDate(s string) bool

func IsValidNumber

func IsValidNumber(s string) bool

检查字符串是不是一个合法的数字

func IsValidTime

func IsValidTime(s string) bool

func IsWechatBrowser

func IsWechatBrowser(userAgent string) bool

func JsonParentPath

func JsonParentPath(params ...string) string

func JsonPath

func JsonPath(params ...string) string

func MkdirAll

func MkdirAll(path string) error

func MobileReplaceRepl

func MobileReplaceRepl(str string) string

func New

func New() string

New returns a new random string of the standard length, consisting of standard characters.

func NewLen

func NewLen(length int) string

NewLen returns a new random string of the provided length, consisting of standard characters.

func NewLenChars

func NewLenChars(length int, chars []byte) string

NewLenChars returns a new random string of the provided length, consisting of the provided byte slice of allowed characters (maximum 256).

func NullData

func NullData(c echo.Context) error

func Open

func Open(uri string) error

func PathExists

func PathExists(path string) (bool, error)

func Read

func Read(path string) string

func ReadByte

func ReadByte(path string) []byte

func Redirect

func Redirect(c echo.Context, url string) error

func RedirectAndAlert

func RedirectAndAlert(c echo.Context, tip, url string) error

func Result

func Result(c echo.Context, ret int64, msg string, data interface{}) error

func ResultApi

func ResultApi(c echo.Context, data interface{}) error

func ResultHtml

func ResultHtml(c echo.Context, html string) error

func ResultString

func ResultString(c echo.Context, str string) error

func Separator

func Separator() string

系统分隔符

func SubStrByByte

func SubStrByByte(str string, length int) string

func SubStrByByteInChar

func SubStrByByteInChar(str string, length int) string

func Substr

func Substr(s string, pos, length int) string

func Success

func Success(c echo.Context, msg string, data interface{}) error

func SuccessNull

func SuccessNull(c echo.Context, msg string) error

func SuccessNullMsg

func SuccessNullMsg(c echo.Context, data interface{}) error

func SuccessRespone

func SuccessRespone(c echo.Context, data string) error

Types

type Command

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

type IdWorker

type IdWorker struct {
	// contains filtered or unexported fields
}
var UUID *IdWorker

func NewIdWorker

func NewIdWorker(NodeId int64) (*IdWorker, error)

NewIdWorker new a snowflake id generator object.

func (*IdWorker) NextId

func (id *IdWorker) NextId() (int64, error)

NextId get a snowflake id.

func (*IdWorker) NextIds

func (id *IdWorker) NextIds(num int) ([]int64, error)

NextIds get snowflake ids.

type Image

type Image struct {
	*image.NRGBA
	// contains filtered or unexported fields
}

func NewImage

func NewImage(digits []byte, width, height int) *Image

func (*Image) WriteTo

func (img *Image) WriteTo(w io.Writer) (int64, error)

type PageData

type PageData struct {
	PageIndex  int
	PageSize   int
	PageNumber int
	Count      int
	Data       []map[string]interface{}
}

type PageTable

type PageTable struct {
	Fields    string
	Table     string
	Where     string
	PageIndex int
	PageSize  int
	Order     string
	Groupby   string
}

type Random

type Random struct{}

Random random

func NewRandom

func NewRandom() *Random

NewRandom new random

func (Random) Number

func (rd Random) Number(length float64) int

Number random number

func (Random) NumberByFloat

func (rd Random) NumberByFloat(start, end float64) float64

func (Random) NumberByInt

func (rd Random) NumberByInt(start, end int) int

func (Random) String

func (rd Random) String(length int) string

String random string

func (Random) ULID

func (rd Random) ULID() string

ULID random ulid

type ResultParam

type ResultParam struct {
	Ret  int64       `json:"ret"`
	Msg  string      `json:"msg"`
	Data interface{} `json:"data"`
}

func ToResultParam

func ToResultParam(b []byte) ResultParam

type SmsClient

type SmsClient struct {
	Request    *model.ALiYunCommunicationRequest
	GatewayUrl string
	Client     *http.Client
}

func NewSmsClient

func NewSmsClient(gatewayUrl string) *SmsClient

func (*SmsClient) Execute

func (smsClient *SmsClient) Execute(accessKeyId, accessKeySecret, phoneNumbers, signName, templateCode, templateParam string) (result map[string]interface{}, err error)

Directories

Path Synopsis
Package query implements encoding of structs into URL query parameters.
Package query implements encoding of structs into URL query parameters.
union
mp
qq

Jump to

Keyboard shortcuts

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