utils

package
v1.6.7 Latest Latest
Warning

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

Go to latest
Published: Feb 27, 2018 License: Apache-2.0 Imports: 12 Imported by: 45

Documentation

Overview

Copyright 2014 loolgame Author. All Rights Reserved.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Copyright 2014 mqant Author. All Rights Reserved.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Copyright 2014 loolgame Author. All Rights Reserved.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Copyright 2014 mqant Author. All Rights Reserved.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Copyright 2014 mqant Author. All Rights Reserved.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Copyright 2014 mqantserver Author. All Rights Reserved.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Copyright 2014 mqantserver Author. All Rights Reserved.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Index

Constants

View Source
const CODE62 = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
View Source
const CODE_LENTH = 62

Variables

View Source
var EDOC = map[string]int64{"0": 0, "1": 1, "2": 2, "3": 3, "4": 4, "5": 5, "6": 6, "7": 7, "8": 8, "9": 9, "a": 10, "b": 11, "c": 12, "d": 13, "e": 14, "f": 15, "g": 16, "h": 17, "i": 18, "j": 19, "k": 20, "l": 21, "m": 22, "n": 23, "o": 24, "p": 25, "q": 26, "r": 27, "s": 28, "t": 29, "u": 30, "v": 31, "w": 32, "x": 33, "y": 34, "z": 35, "A": 36, "B": 37, "C": 38, "D": 39, "E": 40, "F": 41, "G": 42, "H": 43, "I": 44, "J": 45, "K": 46, "L": 47, "M": 48, "N": 49, "O": 50, "P": 51, "Q": 52, "R": 53, "S": 54, "T": 55, "U": 56, "V": 57, "W": 58, "X": 59, "Y": 60, "Z": 61}
View Source
var SHARD_COUNT = 32

Functions

func Base62ToInt

func Base62ToInt(str string) int64

*

  • 解码字符串为整数

func BoolToBytes

func BoolToBytes(v bool) []byte

func BytesToBool

func BytesToBool(buf []byte) bool

func BytesToFloat32

func BytesToFloat32(bytes []byte) float32

func BytesToFloat64

func BytesToFloat64(bytes []byte) float64

func BytesToInt32

func BytesToInt32(buf []byte) int32

func BytesToInt64

func BytesToInt64(buf []byte) int64

func BytesToMap

func BytesToMap(bytes []byte) (map[string]interface{}, error)

func BytesToMapString

func BytesToMapString(bytes []byte) (map[string]string, error)

func Float32ToBytes

func Float32ToBytes(float float32) []byte

func Float64ToBytes

func Float64ToBytes(float float64) []byte

func Go added in v1.6.7

func Go(f func())

func Idle added in v1.6.7

func Idle() bool

func Int32ToBytes

func Int32ToBytes(i int32) []byte

func Int64ToBytes

func Int64ToBytes(i int64) []byte

func IntToBase62

func IntToBase62(number int64) string

*

  • 编码 整数 为 base62 字符串

func MapToBytes

func MapToBytes(jmap map[string]interface{}) ([]byte, error)

func MapToBytesString

func MapToBytesString(jmap map[string]string) ([]byte, error)

func RandInt64

func RandInt64(min, max int64) int64

func Struct2Map

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

Types

type BeeMap

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

BeeMap is a map with lock

func NewBeeMap

func NewBeeMap() *BeeMap

NewBeeMap return new safemap

func (*BeeMap) Check

func (m *BeeMap) Check(k interface{}) bool

Check Returns true if k is exist in the map.

func (*BeeMap) Delete

func (m *BeeMap) Delete(k interface{})

Delete the given key and value.

func (*BeeMap) DeleteAll

func (m *BeeMap) DeleteAll()

func (*BeeMap) Get

func (m *BeeMap) Get(k interface{}) interface{}

Get from maps return the k's value

func (*BeeMap) Items

func (m *BeeMap) Items() map[interface{}]interface{}

Items returns all items in safemap.

func (*BeeMap) Set

func (m *BeeMap) Set(k interface{}, v interface{}) bool

Set Maps the given key and value. Returns false if the key is already in the map and changes nothing.

type ConcurrentMap

type ConcurrentMap []*ConcurrentMapShared

A "thread" safe map of type string:Anything. To avoid lock bottlenecks this map is dived to several (SHARD_COUNT) map shards.

func New

func New() ConcurrentMap

Creates a new concurrent map.

func (ConcurrentMap) Count

func (m ConcurrentMap) Count() int

Returns the number of elements within the map.

func (ConcurrentMap) Get

func (m ConcurrentMap) Get(key string) (interface{}, bool)

Retrieves an element from map under given key.

func (ConcurrentMap) GetShard

func (m ConcurrentMap) GetShard(key string) *ConcurrentMapShared

Returns shard under given key

func (ConcurrentMap) Has

func (m ConcurrentMap) Has(key string) bool

Looks up an item under specified key

func (ConcurrentMap) IsEmpty

func (m ConcurrentMap) IsEmpty() bool

Checks if map is empty.

func (ConcurrentMap) Items

func (m ConcurrentMap) Items() map[string]interface{}

Returns all items as map[string]interface{}

func (ConcurrentMap) Iter deprecated

func (m ConcurrentMap) Iter() <-chan Tuple

Returns an iterator which could be used in a for range loop.

Deprecated: using IterBuffered() will get a better performence

func (ConcurrentMap) IterBuffered

func (m ConcurrentMap) IterBuffered() <-chan Tuple

Returns a buffered iterator which could be used in a for range loop.

func (ConcurrentMap) IterCb

func (m ConcurrentMap) IterCb(fn IterCb)

Callback based iterator, cheapest way to read all elements in a map.

func (ConcurrentMap) Keys

func (m ConcurrentMap) Keys() []string

Return all keys as []string

func (ConcurrentMap) MSet

func (m ConcurrentMap) MSet(data map[string]interface{})

func (ConcurrentMap) MarshalJSON

func (m ConcurrentMap) MarshalJSON() ([]byte, error)

Reviles ConcurrentMap "private" variables to json marshal.

func (ConcurrentMap) Pop

func (m ConcurrentMap) Pop(key string) (v interface{}, exists bool)

Removes an element from the map and returns it

func (ConcurrentMap) Remove

func (m ConcurrentMap) Remove(key string)

Removes an element from the map.

func (ConcurrentMap) RemoveCb

func (m ConcurrentMap) RemoveCb(key string, cb RemoveCb) bool

RemoveCb locks the shard containing the key, retrieves its current value and calls the callback with those params If callback returns true and element exists, it will remove it from the map Returns the value returned by the callback (even if element was not present in the map)

func (ConcurrentMap) Set

func (m ConcurrentMap) Set(key string, value interface{})

Sets the given value under the specified key.

func (ConcurrentMap) SetIfAbsent

func (m ConcurrentMap) SetIfAbsent(key string, value interface{}) bool

Sets the given value under the specified key if no value was associated with it.

func (ConcurrentMap) Upsert

func (m ConcurrentMap) Upsert(key string, value interface{}, cb UpsertCb) (res interface{})

Insert or Update - updates existing element or inserts a new one using UpsertCb

type ConcurrentMapShared

type ConcurrentMapShared struct {
	sync.RWMutex // Read Write mutex, guards access to internal map.
	// contains filtered or unexported fields
}

A "thread" safe string to anything map.

type IterCb

type IterCb func(key string, v interface{})

Iterator callback,called for every key,value found in maps. RLock is held for all calls for a given shard therefore callback sess consistent view of a shard, but not across the shards

type RedisFactory

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

func GetRedisFactory

func GetRedisFactory() *RedisFactory

func (RedisFactory) CloseAllPool

func (this RedisFactory) CloseAllPool()

func (RedisFactory) GetPool

func (this RedisFactory) GetPool(url string) *redis.Pool

type RemoveCb

type RemoveCb func(key string, v interface{}, exists bool) bool

RemoveCb is a callback executed in a map.RemoveCb() call, while Lock is held If returns true, the element will be removed from the map

type Tuple

type Tuple struct {
	Key string
	Val interface{}
}

Used by the Iter & IterBuffered functions to wrap two variables together over a channel,

type UpsertCb

type UpsertCb func(exist bool, valueInMap interface{}, newValue interface{}) interface{}

Callback to return new element to be inserted into the map It is called while lock is held, therefore it MUST NOT try to access other keys in same map, as it can lead to deadlock since Go sync.RWLock is not reentrant

Directories

Path Synopsis
fatih
structs
Package structs contains various utilities functions to work with structs.
Package structs contains various utilities functions to work with structs.
x
crypto/acme
Package acme provides an implementation of the Automatic Certificate Management Environment (ACME) spec.
Package acme provides an implementation of the Automatic Certificate Management Environment (ACME) spec.
crypto/acme/autocert
Package autocert provides automatic access to certificates from Let's Encrypt and any other ACME-based CA.
Package autocert provides automatic access to certificates from Let's Encrypt and any other ACME-based CA.
crypto/bcrypt
Package bcrypt implements Provos and Mazières's bcrypt adaptive hashing algorithm.
Package bcrypt implements Provos and Mazières's bcrypt adaptive hashing algorithm.
crypto/blake2b
Package blake2b implements the BLAKE2b hash algorithm as defined in RFC 7693.
Package blake2b implements the BLAKE2b hash algorithm as defined in RFC 7693.
crypto/blake2s
Package blake2s implements the BLAKE2s hash algorithm as defined in RFC 7693.
Package blake2s implements the BLAKE2s hash algorithm as defined in RFC 7693.
crypto/blowfish
Package blowfish implements Bruce Schneier's Blowfish encryption algorithm.
Package blowfish implements Bruce Schneier's Blowfish encryption algorithm.
crypto/bn256
Package bn256 implements a particular bilinear group at the 128-bit security level.
Package bn256 implements a particular bilinear group at the 128-bit security level.
crypto/cast5
Package cast5 implements CAST5, as defined in RFC 2144.
Package cast5 implements CAST5, as defined in RFC 2144.
crypto/chacha20poly1305
Package chacha20poly1305 implements the ChaCha20-Poly1305 AEAD as specified in RFC 7539.
Package chacha20poly1305 implements the ChaCha20-Poly1305 AEAD as specified in RFC 7539.
crypto/chacha20poly1305/internal/chacha20
Package ChaCha20 implements the core ChaCha20 function as specified in https://tools.ietf.org/html/rfc7539#section-2.3.
Package ChaCha20 implements the core ChaCha20 function as specified in https://tools.ietf.org/html/rfc7539#section-2.3.
crypto/curve25519
Package curve25519 provides an implementation of scalar multiplication on the elliptic curve known as curve25519.
Package curve25519 provides an implementation of scalar multiplication on the elliptic curve known as curve25519.
crypto/ed25519
Package ed25519 implements the Ed25519 signature algorithm.
Package ed25519 implements the Ed25519 signature algorithm.
crypto/hkdf
Package hkdf implements the HMAC-based Extract-and-Expand Key Derivation Function (HKDF) as defined in RFC 5869.
Package hkdf implements the HMAC-based Extract-and-Expand Key Derivation Function (HKDF) as defined in RFC 5869.
crypto/md4
Package md4 implements the MD4 hash algorithm as defined in RFC 1320.
Package md4 implements the MD4 hash algorithm as defined in RFC 1320.
crypto/nacl/box
Package box authenticates and encrypts messages using public-key cryptography.
Package box authenticates and encrypts messages using public-key cryptography.
crypto/nacl/secretbox
Package secretbox encrypts and authenticates small messages.
Package secretbox encrypts and authenticates small messages.
crypto/ocsp
Package ocsp parses OCSP responses as specified in RFC 2560.
Package ocsp parses OCSP responses as specified in RFC 2560.
crypto/openpgp
Package openpgp implements high level operations on OpenPGP messages.
Package openpgp implements high level operations on OpenPGP messages.
crypto/openpgp/armor
Package armor implements OpenPGP ASCII Armor, see RFC 4880.
Package armor implements OpenPGP ASCII Armor, see RFC 4880.
crypto/openpgp/clearsign
Package clearsign generates and processes OpenPGP, clear-signed data.
Package clearsign generates and processes OpenPGP, clear-signed data.
crypto/openpgp/elgamal
Package elgamal implements ElGamal encryption, suitable for OpenPGP, as specified in "A Public-Key Cryptosystem and a Signature Scheme Based on Discrete Logarithms," IEEE Transactions on Information Theory, v.
Package elgamal implements ElGamal encryption, suitable for OpenPGP, as specified in "A Public-Key Cryptosystem and a Signature Scheme Based on Discrete Logarithms," IEEE Transactions on Information Theory, v.
crypto/openpgp/errors
Package errors contains common error types for the OpenPGP packages.
Package errors contains common error types for the OpenPGP packages.
crypto/openpgp/packet
Package packet implements parsing and serialization of OpenPGP packets, as specified in RFC 4880.
Package packet implements parsing and serialization of OpenPGP packets, as specified in RFC 4880.
crypto/openpgp/s2k
Package s2k implements the various OpenPGP string-to-key transforms as specified in RFC 4800 section 3.7.1.
Package s2k implements the various OpenPGP string-to-key transforms as specified in RFC 4800 section 3.7.1.
crypto/otr
Package otr implements the Off The Record protocol as specified in http://www.cypherpunks.ca/otr/Protocol-v2-3.1.0.html
Package otr implements the Off The Record protocol as specified in http://www.cypherpunks.ca/otr/Protocol-v2-3.1.0.html
crypto/pbkdf2
Package pbkdf2 implements the key derivation function PBKDF2 as defined in RFC 2898 / PKCS #5 v2.0.
Package pbkdf2 implements the key derivation function PBKDF2 as defined in RFC 2898 / PKCS #5 v2.0.
crypto/pkcs12
Package pkcs12 implements some of PKCS#12.
Package pkcs12 implements some of PKCS#12.
crypto/pkcs12/internal/rc2
Package rc2 implements the RC2 cipher https://www.ietf.org/rfc/rfc2268.txt http://people.csail.mit.edu/rivest/pubs/KRRR98.pdf This code is licensed under the MIT license.
Package rc2 implements the RC2 cipher https://www.ietf.org/rfc/rfc2268.txt http://people.csail.mit.edu/rivest/pubs/KRRR98.pdf This code is licensed under the MIT license.
crypto/poly1305
Package poly1305 implements Poly1305 one-time message authentication code as specified in http://cr.yp.to/mac/poly1305-20050329.pdf.
Package poly1305 implements Poly1305 one-time message authentication code as specified in http://cr.yp.to/mac/poly1305-20050329.pdf.
crypto/ripemd160
Package ripemd160 implements the RIPEMD-160 hash algorithm.
Package ripemd160 implements the RIPEMD-160 hash algorithm.
crypto/salsa20
Package salsa20 implements the Salsa20 stream cipher as specified in http://cr.yp.to/snuffle/spec.pdf.
Package salsa20 implements the Salsa20 stream cipher as specified in http://cr.yp.to/snuffle/spec.pdf.
crypto/salsa20/salsa
Package salsa provides low-level access to functions in the Salsa family.
Package salsa provides low-level access to functions in the Salsa family.
crypto/scrypt
Package scrypt implements the scrypt key derivation function as defined in Colin Percival's paper "Stronger Key Derivation via Sequential Memory-Hard Functions" (http://www.tarsnap.com/scrypt/scrypt.pdf).
Package scrypt implements the scrypt key derivation function as defined in Colin Percival's paper "Stronger Key Derivation via Sequential Memory-Hard Functions" (http://www.tarsnap.com/scrypt/scrypt.pdf).
crypto/sha3
Package sha3 implements the SHA-3 fixed-output-length hash functions and the SHAKE variable-output-length hash functions defined by FIPS-202.
Package sha3 implements the SHA-3 fixed-output-length hash functions and the SHAKE variable-output-length hash functions defined by FIPS-202.
crypto/ssh
Package ssh implements an SSH client and server.
Package ssh implements an SSH client and server.
crypto/ssh/agent
Package agent implements the ssh-agent protocol, and provides both a client and a server.
Package agent implements the ssh-agent protocol, and provides both a client and a server.
crypto/ssh/terminal
Package terminal provides support functions for dealing with terminals, as commonly found on UNIX systems.
Package terminal provides support functions for dealing with terminals, as commonly found on UNIX systems.
crypto/ssh/test
This package contains integration tests for the
This package contains integration tests for the
crypto/twofish
Package twofish implements Bruce Schneier's Twofish encryption algorithm.
Package twofish implements Bruce Schneier's Twofish encryption algorithm.
crypto/xtea
Package xtea implements XTEA encryption, as defined in Needham and Wheeler's 1997 technical report, "Tea extensions."
Package xtea implements XTEA encryption, as defined in Needham and Wheeler's 1997 technical report, "Tea extensions."
crypto/xts
Package xts implements the XTS cipher mode as specified in IEEE P1619/D16.
Package xts implements the XTS cipher mode as specified in IEEE P1619/D16.

Jump to

Keyboard shortcuts

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