Documentation ¶
Index ¶
- Constants
- Variables
- func Chk(err error)
- func Filter[T any](collection []T, fn func(T) bool) []T
- func FilterMap[T any, R any](collection []T, fn func(T) (R, bool)) []R
- func Finish(ctx context.Context, concurrent int, fn ...func() error) error
- func FinishWithGen(ctx context.Context, concurrent int, gen func(source chan<- func() error)) error
- func FlatMap[T any, R any](collection []T, fn func(T) []R) []R
- func HmacSha256(s string, key string) string
- func HttpGet(getUrl string, credential ...string) ([]byte, error)
- func HttpGet2(getUrl string, contentType string, opt *HttpOpt) ([]byte, error)
- func HttpPost(postUrl string, q url.Values, credential ...string) ([]byte, error)
- func HttpPost2(postUrl string, contentType string, body io.Reader, opt *HttpOpt) ([]byte, error)
- func IsPemExpire(b []byte) (bool, error)
- func Map[T any, R any](collection []T, fn func(T) R) []R
- func Max[T cmp.Ordered](n ...T) T
- func Md5(b []byte) []byte
- func Md5Str(salt string) func(string) string
- func Min[T cmp.Ordered](n ...T) T
- func OrderBy[T any, R cmp.Ordered](l []T, fn func(T) R) []T
- func OrderByDescending[T any, R cmp.Ordered](l []T, fn func(T) R) []T
- func ParseAddr(s string) (string, int, error)
- func PasswdHash(password string, cost ...int) (string, error)
- func Reject[T any](collection []T, fn func(T) bool) []T
- func SetHttpClient(hc *http.Client)
- func Sha1Str(salt string) func(string) string
- func Sha256Str(salt string) func(string) string
- func Shuffle[T any](collection []T) []T
- func SplitSliceIntoN[T any](a []T, n int) [][]T
- func TimeBetween(check, start, end time.Time) bool
- func Truncate(s string, maxLen uint) string
- func VerifyPasswd(password, hash string) bool
- func Zip(pathToZip string, dest io.Writer) error
- type BasicAuth
- type HttpOpt
- type J
- type MemQueue
- type PerfLog
- type Throttle
- type Tick
- type TimerCache2
Constants ¶
const ( MAX_HTTP_CLIENT_CONCURRENT = 1000 ContentTypeForm = "application/x-www-form-urlencoded" ContentTypeJson = "application/json; charset=utf-8" )
Variables ¶
var ( // PlainMd5 string md5 function with empty salt PlainMd5 = Md5Str("") // PlainSha1 string sha-1 function with empty salt PlainSha1 = Sha1Str("") )
var (
ErrEmptyHeaderName = errors.New("header name must not be empty")
)
var ErrFull = errors.New("queue is full")
Functions ¶
func Finish ¶ added in v1.4.9
Finish concurrent run fn, return error if any of fn return error similar to mapreduce.Finish, but with concurrent limit concurrent , limit of map reduce concurrency
func FinishWithGen ¶ added in v1.4.10
FinishWithGen concurrent run fn (which is generated by gen), return error if any of fn return error concurrent , limit of map reduce concurrency
func HmacSha256 ¶
func IsPemExpire ¶
func OrderByDescending ¶ added in v1.3.0
OrderByDescending order by fn descending, return ordered copy of slice
func PasswdHash ¶ added in v1.4.5
PasswdHash generate password hash, compatible with PHP Yii framework
func SetHttpClient ¶ added in v1.2.7
SetHttpClient expose HTTP Client for further customize
func SplitSliceIntoN ¶ added in v1.4.7
SplitSliceIntoN split slice into several parts, no more than n
func TimeBetween ¶ added in v1.4.16
TimeBetween check if check time is between start and end
func Truncate ¶
Truncate , truncate string as []rune make sure the rune count of result is not more than maxLen
func VerifyPasswd ¶ added in v1.4.5
VerifyPasswd validate password,compatible with PHP Yii framework
Types ¶
type MemQueue ¶
type MemQueue chan interface{}
MemQueue memory queue
func (MemQueue) EnqBlocking ¶
func (p MemQueue) EnqBlocking(data interface{})
EnqBlocking enqueue, block if queue is full
type Throttle ¶
type Throttle struct {
// contains filtered or unexported fields
}
Throttle , limit number of concurrent goroutines
func NewThrottle ¶
NewThrottle New Throttle max , max number of this throttle
type Tick ¶
type Tick int64
Tick unix timestamp in millisecond
type TimerCache2 ¶ added in v1.4.0
type TimerCache2[K comparable, V any] struct { // contains filtered or unexported fields }
TimerCache2 generic timer cache
func NewTimerCache2 ¶ added in v1.4.0
func NewTimerCache2[K comparable, V any](ttl int, expireCb ...func(key K, value V)) *TimerCache2[K, V]
NewTimerCache2 create new TimerCache2 ttl in second expireCb, expire callback
func (*TimerCache2[K, V]) Get ¶ added in v1.4.0
func (p *TimerCache2[K, V]) Get(key K) (V, bool)
func (*TimerCache2[K, V]) Keys ¶ added in v1.4.0
func (p *TimerCache2[K, V]) Keys() []K
func (*TimerCache2[K, V]) Len ¶ added in v1.4.0
func (p *TimerCache2[K, V]) Len() int
func (*TimerCache2[K, V]) Put ¶ added in v1.4.0
func (p *TimerCache2[K, V]) Put(key K, val V) bool
func (*TimerCache2[K, V]) Remove ¶ added in v1.4.0
func (p *TimerCache2[K, V]) Remove(key K) (V, bool)
func (*TimerCache2[K, V]) TTL ¶ added in v1.4.0
func (p *TimerCache2[K, V]) TTL(key K) (int64, bool)
TTL Check ttl (in second)