utils

package
v0.0.0-...-f84f93e Latest Latest
Warning

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

Go to latest
Published: May 30, 2018 License: Apache-2.0 Imports: 22 Imported by: 0

Documentation

Overview

*********************************************************

  • Author : Michael
  • Email : dolotech@163.com
  • Last modified : 2016-04-30 09:40
  • Filename : debug.go
  • Description :
  • ******************************************************

线程安全的数组封装,注意:写锁接口不能嵌套调用,比如:Range接口不能调用删除接口Del

Index

Constants

View Source
const FORMAT string = "2006-01-02 15:04:05"
View Source
const FORMATDATA string = "2006-01-02 "

Variables

View Source
var IllegalNameRune = [13]rune{0x00, 0x09, 0x5f, 0x20, 0x22, 0x60, 0x1a, 0x0a, 0x0d, 0x27, 0x25, 0x5c, 0x2c}

不可见字符,用于用户提交的字符过滤分别对应为:,\0 \t _ space " ` ctrl+z \n \r ` % \ ,

Functions

func AalidataPwd

func AalidataPwd(name string) (b bool)

验证只能由数字字母下划线组成的5-17位密码字符串

func AccountRegexp

func AccountRegexp(account string) bool

验证账号是否合法

func Base62decode

func Base62decode(base62 string) uint64

func Base62encode

func Base62encode(num uint64) string

func BytesToInt

func BytesToInt(b []byte) int

字节转换成整形

func BytesToInt64

func BytesToInt64(b []byte) int64

字节转换成整形

func Clone

func Clone(dst, src interface{}) error

对象深度拷贝

func DateStr

func DateStr() string

str格式当前日期

func Day

func Day() int

获取当前天

func Decode

func Decode(data []byte, to interface{}) error

用gob进行数据解码

func Decrypt

func Decrypt(data []byte, key []byte) []byte

Decrypt the data with key. data is the bytes to be decrypted. key is the decrypted key. It is the same as the encrypt key.

func Dump

func Dump(v interface{})

Print to standard out the value that is passed as the argument with indentation. Pointers are dereferenced.

func EmailRegexp

func EmailRegexp(mail string) bool

验证是否邮箱

func Encode

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

用gob进行数据编码

func Encrypt

func Encrypt(data []byte, key []byte) []byte

Encrypt the data with key. data is the bytes to be encrypted. key is the encrypt key. It is the same as the decrypt key.

func GCSummary

func GCSummary() string

func GetAuth

func GetAuth() []rune

func InetToaton

func InetToaton(ipnr string) uint32

点分结构的IP地址转成数值类型 eg: t.Log((InetToaton("192.168.1.190")))

func InetTobton

func InetTobton(ipnr net.IP) uint32

字节类型的IP地址转成数值类型 t.Log((InetTobton(net.IPv4(192,168,1,190))))

func InetTontoa

func InetTontoa(ipnr uint32) net.IP

数值类型转成点分结构的IP地址 eg: t.Log((InetTontoa(3232235966).String()))

func Int64ToBytes

func Int64ToBytes(n int64) []byte

整形转换成字节

func IntToBytes

func IntToBytes(n int) []byte

整形转换成字节

func LegalName

func LegalName(name string, maxcount int) bool

限制最大字符数,检测不可见字符 maxcount 限制的最大字符数,1个中文=2个英文

func Md5

func Md5(text string) string

md5 加密

func Md5(text string) string {
	hashMd5 := md5.New()
	io.WriteString(hashMd5, text)
	return fmt.Sprintf("%x", hashMd5.Sum(nil))
}

func Month

func Month() time.Month

获取当前月

func MonthDays

func MonthDays(year int, month int) (days int)

获取指定年月的天数

func PhoneRegexp

func PhoneRegexp(phone string) bool

验证是否手机

func RandInt32

func RandInt32() (r int32)

func RandInt32N

func RandInt32N(n int32) (r int32)

func RandInt64

func RandInt64() (r int64)

func RandInt64N

func RandInt64N(n int64) (r int64)

func RandUint32

func RandUint32() (r uint32)

func Sdump

func Sdump(v interface{}) string

Return the value that is passed as the argument with indentation. Pointers are dereferenced.

func Sleep

func Sleep(second int)

延迟second

func Sleep64

func Sleep64(second int64)

延迟second

func SleepRand

func SleepRand(second int)

延迟1~second

func SleepRand64

func SleepRand64(second int64)

延迟1~second

func SliceIndexOf

func SliceIndexOf(arr []string, str string) int

切片中字符串第一个位置

func SliceLastIndexOf

func SliceLastIndexOf(arr []string, str string) int

字节转换成整形

func SliceRemoveFormSlice

func SliceRemoveFormSlice(oriArr []string, removeArr []string) []string

字节转换成整形

func Str2Unix

func Str2Unix(t string) (int64, error)

str格式化时间转时间戳

func StringAdd

func StringAdd(numStr string) string

字符串加法

func Struct2Map

func Struct2Map(obj interface{}) map[string]interface{}

func SubStr

func SubStr(str string, begin, length int) (substr string)

*

  • 截取字符串
  • @param string str
  • @param begin int
  • @param length int
  • @return int 长度

func TimeToHeadphpoto

func TimeToHeadphpoto(t int64, userid int, headname int64) (string, string)

把时间戳转换成头像存储目录

func TimeToPhpotoPath

func TimeToPhpotoPath(t int64, userid int) string

把时间戳转换成头像存储目录

func Timestamp

func Timestamp() int64

获取当前时间截

func TimestampNano

func TimestampNano() int64

获取当前时间截

func TimestampSaturday

func TimestampSaturday() int64

获取本周六零点时间截

func TimestampToday

func TimestampToday() int64

获取本地当天零点时间截

func TimestampTomorrow

func TimestampTomorrow() int64

获取本地明天零点时间截

func TimestampYesterday

func TimestampYesterday() int64

获取本地昨天零点时间截

func Unix2Day

func Unix2Day(t int64) int

获取指定时间截的天

func Unix2Month

func Unix2Month(t int64) time.Month

获取指定时间截的月

func Unix2Str

func Unix2Str(t int64) string

时间戳转str格式化时间

func Unix2Year

func Unix2Year(t int64) int

获取指定时间截的年

func UseridCovToInvate

func UseridCovToInvate(userid string) uint32

func Weekday

func Weekday() time.Weekday

获取当前周

func Year

func Year() int

获取当前年

Types

type AesEncrypt

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

func (*AesEncrypt) Decrypt

func (this *AesEncrypt) Decrypt(src []byte) (strDesc []byte, err error)

解密字符串

func (*AesEncrypt) Encrypt

func (this *AesEncrypt) Encrypt(strMesg []byte) ([]byte, error)

加密字符串

func (*AesEncrypt) SetKey

func (this *AesEncrypt) SetKey(key []byte)

type Array

type Array interface {
	//Push 向链表尾部添加一个或者多个元素
	Push(values ...interface{})

	// Pop 从列表尾部移除并返回一个元素
	Pop() interface{}

	//PushFront 向链表头部添加一个元素
	PushFront(values ...interface{})

	// PopFront从链表头部移除并返回一个元素
	PopFront() interface{}

	// Len 返回集链表元素的长度
	Len() int

	// Values 返回链表所有元素组成的 Slice
	Values() []interface{}

	// Iter 遍历链表的所有元素
	Iter() <-chan interface{}

	// Clear  清空链表
	Clear()
}

func NewArray

func NewArray(block bool, values ...interface{}) Array

NewArray 创建一个链表,block == true :线程安全,block == false:非线程安全

type List

type List struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

func NewList

func NewList() *List

func (*List) Add

func (this *List) Add(value interface{})

func (*List) Del

func (this *List) Del(value interface{})

func (*List) Delete

func (this *List) Delete(f func(interface{}) bool)

func (*List) Get

func (this *List) Get(f func(interface{}) bool) interface{}

func (*List) LRange

func (this *List) LRange(f func(interface{}) bool)

func (*List) Len

func (this *List) Len() int

func (*List) Pure

func (this *List) Pure()

func (*List) Range

func (this *List) Range(f func(interface{}) bool)

func (*List) Replace

func (this *List) Replace(value interface{}, f func(interface{}) bool)

type Map

type Map struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

func NewMap

func NewMap() *Map

func (*Map) Del

func (this *Map) Del(key interface{})

func (*Map) Exist

func (this *Map) Exist(key interface{}) bool

func (*Map) Get

func (this *Map) Get(key interface{}) interface{}

func (*Map) Iter

func (this *Map) Iter() <-chan interface{}

func (*Map) LRange

func (this *Map) LRange(f func(interface{}, interface{}) bool)

func (*Map) Len

func (this *Map) Len() int

func (*Map) Range

func (this *Map) Range(f func(interface{}, interface{}) bool)

func (*Map) Set

func (this *Map) Set(key interface{}, value interface{}) bool

type Queue

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

func (*Queue) Len

func (q *Queue) Len() int

func (*Queue) Pop

func (q *Queue) Pop() (elem interface{})

func (*Queue) Push

func (q *Queue) Push(elem interface{})

type RPCConfig

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

func (*RPCConfig) FillStruct

func (s *RPCConfig) FillStruct(m map[string]string) error

type TimeOuter

type TimeOuter interface {
	TimeOut(int64)
}

type Timer

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

type TimerManager

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

func NewTimerManager

func NewTimerManager(size int) *TimerManager

func (*TimerManager) AddTimer

func (this *TimerManager) AddTimer(i TimeOuter, e int64, iv int64) uint32

func (*TimerManager) RemoveTimer

func (this *TimerManager) RemoveTimer(id uint32)

func (*TimerManager) Run

func (this *TimerManager) Run(now int64, limit int)

type TimerQueue

type TimerQueue []*Timer

func (TimerQueue) Len

func (this TimerQueue) Len() int

func (TimerQueue) Less

func (this TimerQueue) Less(i, j int) bool

func (*TimerQueue) Pop

func (this *TimerQueue) Pop() interface{}

func (*TimerQueue) Push

func (this *TimerQueue) Push(x interface{})

func (TimerQueue) Swap

func (this TimerQueue) Swap(i, j int)

Jump to

Keyboard shortcuts

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