helper

package module
v0.0.0-...-3ae2b74 Latest Latest
Warning

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

Go to latest
Published: Sep 7, 2019 License: Apache-2.0 Imports: 49 Imported by: 1

Documentation

Index

Constants

View Source
const RedisDsyncLockKey = "dsynclock:topic:"

Variables

View Source
var (
	V_REGEXP_PHONE    = "^(1(([35][0-9])|[8][0-9]|[7][0-9]|[4][579]))\\d{8}$"
	V_REGEXP_USERNAME = "^[a-zA-Z0-9_]{4,16}$"
	V_REGEXP_PASSWORD = "^(?=.*\\d)(?=.*[a-z])(?=.*[A-Z]).{6,10}$"
	V_REGEXP_NICK     = "^[\u4E00-\u9FA5A-Za-z0-9_]{2,12}$"
	V_REGEXP_EMAIL    = "[\\w!#$%&'*+/=?^_`{|}~-]+(?:\\.[\\w!#$%&'*+/=?^_`{|}~-]+)*@(?:[\\w](?:[\\w-]*[\\w])?\\.)+[\\w](?:[\\w-]*[\\w])?"
	V_REGEXP_CHINESE  = "^[\\u4e00-\\u9fa5]{0,}$"
	V_REGEXP_MONEY    = "^[0-9]+(.[0-9]{2})?$"
	V_REGEXP_IPv4     = "\\b(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\b"
)
View Source
var GMgoConnectionStringURI = ""

mgo.PrimaryPreferred 5 mode: primary Perform all read operations on the master node primaryPreferred Priority on the main node to read, if the primary node is not available, and then from the slave operation secondary All read operations are performed on the slave node secondaryPreferred Priority to read from the slave node, if all slave nodes are unavailable, and then from the master node operation。 nearest According to the network delay time, the nearest read operation, regardless of the node type。 default is strong mode its named primary. eg. gMgoSession.SetMode(mgo.Strong)

View Source
var GMgoDatabaseName = ""
View Source
var GMongo *mongo.Database
View Source
var GRedis *redis.Client
View Source
var GRedisRing *redis.Ring
View Source
var MysqlEngine *xorm.Engine
View Source
var RandNumTmps = []byte("0123456789")

0123456789 select 6 password number

View Source
var SigAlreadyRegisted = errors.New("sig already registed")

Functions

func Byte2String

func Byte2String(b []byte) string

data convert

func CBCDecrypter

func CBCDecrypter(keys string, endata string, ivs string) ([]byte, error)

func Chaos

func Chaos(fn string, f ...func())

func ChaosDB

func ChaosDB()

func Cputicks

func Cputicks() (t uint64)

func GenOrderNo

func GenOrderNo(userId string) string

func Get

func Get(address string, isKeep bool) ([]byte, error)

func GetCurrentDirectory

func GetCurrentDirectory() string

func GetLocalIP

func GetLocalIP() string

func GetPwd

func GetPwd() string

func GetUrlencoded

func GetUrlencoded(address string, isKeep bool, data map[string]string) ([]byte, error)

func HTTPInstance

func HTTPInstance() *http.Client

func HTTPTLSInstance

func HTTPTLSInstance(certFile, keyFile string) *http.Client

func HmacSha1

func HmacSha1(src, key string) string

func Int64Range

func Int64Range(min, max int64) int64

[min,max]

func IsASCII

func IsASCII(s string) bool

func IsAllNotNilString

func IsAllNotNilString(s ...string) bool

func IsChinese

func IsChinese(chars string, regex ...string) bool

func IsEmail

func IsEmail(mail string, regex ...string) bool

func IsFileExist

func IsFileExist(f string) bool

func IsIPv4

func IsIPv4(ip string, regex ...string) bool

func IsInStringSlice

func IsInStringSlice(dst string, src []string) bool

func IsMoney2Point

func IsMoney2Point(s string, regex ...string) bool

func IsNick

func IsNick(nick string, regex ...string) bool

func IsNilString

func IsNilString(s string) bool

func IsNotNilString

func IsNotNilString(s string) bool

func IsPassword

func IsPassword(pwd string, regex ...string) bool

func IsPhone

func IsPhone(phone string, regex ...string) bool

validator string、phone、email etc.

func IsUserName

func IsUserName(userName string, regex ...string) bool

func MD5

func MD5(b []byte) string

func MD5BySalt

func MD5BySalt(src, salt string) string

commonly used secret function

func MakeSpecId

func MakeSpecId() string

func Marshal2Bytes

func Marshal2Bytes(data interface{}) (s []byte)

func Marshal2String

func Marshal2String(data interface{}) (s string)

func MgoChaos

func MgoChaos()

func MgoExecute

func MgoExecute(colName string, q func(*mgo.Collection) error) error

func MgoExecuteBulk

func MgoExecuteBulk(colName string, q func(*mgo.Bulk) error) error

func MinQuantity

func MinQuantity(v uint32) uint32

round 到最近的2的倍数

func MongodbInstance

func MongodbInstance()

func MustMarshal2String

func MustMarshal2String(v interface{}) string

func MustXMll2Byte

func MustXMll2Byte(v interface{}) []byte

func MysqlChaos

func MysqlChaos() *xorm.Engine

func NewDLock

func NewDLock(topic string, timeOut time.Duration) *lock.Locker

func NewMgoSession

func NewMgoSession() *mgo.Session

func NextZeroDateWithSub

func NextZeroDateWithSub() (time.Time, time.Time)

func NormFloat64

func NormFloat64(num int, sq, ar float64) (f []float64)

func PBMarshal2String

func PBMarshal2String(data proto.Message) (s string)

func Post

func Post(address, contentType string, isKeep bool, data []byte) ([]byte, error)

func PostRawJson

func PostRawJson(address string, isKeep bool, data []byte) ([]byte, error)

func PostUrlencoded

func PostUrlencoded(address string, isKeep bool, data map[string]string) ([]byte, error)

func RandId

func RandId() string

uuid+unix time

func RandIdInt64

func RandIdInt64() int64

func RandInt

func RandInt(min, max int) int

func RandInt32

func RandInt32(min, max int32) int32

func RandNumber

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

func RandUInt32

func RandUInt32(min, max uint32) uint32

func RandUInt64

func RandUInt64(min, max uint64) uint64

func RandomLetters

func RandomLetters(n int, alphabets ...byte) string

func RedisChaos

func RedisChaos()

func RedisInstance

func RedisInstance()

func RegisterContinueSignal

func RegisterContinueSignal(sig os.Signal, process func()) error

func RegisterSignal

func RegisterSignal(sig os.Signal, process func()) error

func Round

func Round(f float64, n int) float64

func SHA1

func SHA1(src string) string

func SHA1BySalt

func SHA1BySalt(src, salt string) (string, error)

func SetExpireAt

func SetExpireAt(key string, value interface{}, t time.Time) error

func Sha1

func Sha1(query string, pri_key string) string

func SignalProcessed

func SignalProcessed(sig os.Signal) bool

func String2ASCII

func String2ASCII(s string) string

to ascii

func String2Byte

func String2Byte(s string) []byte

func Struct2Map

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

func Struct2MapInterface

func Struct2MapInterface(in interface{}, tag string) map[string]interface{}

Types

type B64Encoding

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

func B64NewEncoding

func B64NewEncoding(s string) *B64Encoding

func (*B64Encoding) B64Decode

func (b *B64Encoding) B64Decode(s string) string

func (*B64Encoding) B64Encode

func (b *B64Encoding) B64Encode(s string) string

type ConcurrentMap

type ConcurrentMap []*ConcurrentMapShared

func New

func New() ConcurrentMap

func (ConcurrentMap) Get

func (c ConcurrentMap) Get(key uint64) (interface{}, bool)

func (ConcurrentMap) Remove

func (c ConcurrentMap) Remove(key uint64)

func (ConcurrentMap) Set

func (c ConcurrentMap) Set(key uint64, value interface{})

type ConcurrentMapShared

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

type Email

type Email struct {
	UserName   string
	Host       string
	Port       string
	Password   string
	To         []string
	ToString   string
	EmailAlias string
	Subject    string

	ContentType []byte
	// contains filtered or unexported fields
}

func EmailInstance

func EmailInstance() *Email

func (*Email) SendMail

func (e *Email) SendMail(content string)

type ForXmlMap

type ForXmlMap map[string]interface{}

func (ForXmlMap) MarshalXML

func (m ForXmlMap) MarshalXML(e *xml.Encoder, start xml.StartElement) error

func (*ForXmlMap) UnmarshalXML

func (m *ForXmlMap) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error

Jump to

Keyboard shortcuts

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