utee

package module
v1.2.8 Latest Latest
Warning

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

Go to latest
Published: Apr 10, 2021 License: MIT Imports: 24 Imported by: 114

README

utee

utilities for golang

Documentation

Index

Constants

View Source
const (
	MAX_HTTP_CLIENT_CONCURRENT = 1000

	ContentTypeForm = "application/x-www-form-urlencoded"
	ContentTypeJson = "application/json; charset=utf-8"
)

Variables

View Source
var (
	// PlainMd5 string md5 function with empty salt
	PlainMd5 = Md5Str("")
	// PlainMd5 string sha-1 function with empty salt
	PlainSha1 = Sha1Str("")
)
View Source
var (
	ErrEmptyHeaderName = errors.New("header name must not be empty")
)
View Source
var ErrFull = errors.New("queue is full")

Functions

func Chk

func Chk(err error)

func HmacSha256

func HmacSha256(s string, key string) string

func HttpGet

func HttpGet(getUrl string, credential ...string) ([]byte, error)

func HttpGet2

func HttpGet2(getUrl string, contentType string, opt *HttpOpt) ([]byte, error)

func HttpPost

func HttpPost(postUrl string, q url.Values, credential ...string) ([]byte, error)

func HttpPost2

func HttpPost2(postUrl string, contentType string, body io.Reader, opt *HttpOpt) ([]byte, error)

func IntToInf

func IntToInf(src []int) []interface{}

func IsPemExpire

func IsPemExpire(b []byte) (bool, error)

func Md5

func Md5(b []byte) []byte

func Md5Str

func Md5Str(salt string) func(string) string

Md5Str create string md5 function with salt

func MultiDeleteFromMap added in v1.2.2

func MultiDeleteFromMap(m map[string]interface{}, ks ...string)

func ParseAddr

func ParseAddr(s string) (string, int, error)

func SendMail

func SendMail(user, password, host, to, subject, body, mailtype string) error

func SetHttpClient added in v1.2.7

func SetHttpClient(hc *http.Client)

HTTP Client expose for further customize

func Sha1Str

func Sha1Str(salt string) func(string) string

Sha1Str create string sha-1 function with salt

func Sha256Str

func Sha256Str(salt string) func(string) string

Sha256Str create string sha-256 function with salt

func Shuffle

func Shuffle(src []string) []string

func SplitIntSlice added in v1.2.8

func SplitIntSlice(src []int, chunkSize int) [][]int

SplitIntSlice split int slice into chunks

func SplitStringSlice added in v1.2.8

func SplitStringSlice(src []string, chunkSize int) [][]string

SplitStringSlice split string slice into chunks

func SplitStringSliceIntoN added in v1.2.8

func SplitStringSliceIntoN(a []string, n int) [][]string

SplitStringSliceIntoN split a into several parts, no more than n

func StrToInf

func StrToInf(src []string) []interface{}

func Truncate

func Truncate(s string, n int) string

Truncate truncate string

func Unique added in v1.1.1

func Unique(data []interface{}) []interface{}

func UniqueInt added in v1.1.1

func UniqueInt(data []int) []int

func UniqueStr added in v1.1.1

func UniqueStr(data []string) []string

Types

type BasicAuth

type BasicAuth struct {
	Username string
	Password string
}

type HttpOpt

type HttpOpt struct {
	Headers   map[string]string
	BasicAuth *BasicAuth
}

type J

type J map[string]interface{}

func (J) ToReader added in v1.2.5

func (p J) ToReader() io.Reader

func (J) ToString added in v1.2.5

func (p J) ToString() string

type MemQueue

type MemQueue chan interface{}

MemQueue memory queue

func NewLeakMemQueue

func NewLeakMemQueue(cap, concurrent int, worker func(interface{})) MemQueue

NewLeakMemQueue create memory queue, auto-leak element concurrently to worker

func NewMemQueue

func NewMemQueue(cap int) MemQueue

NewMemQueue create memory queue

func (MemQueue) Cap

func (p MemQueue) Cap() int

Cap queue capacity

func (MemQueue) Deq

func (p MemQueue) Deq() interface{}

Deq

func (MemQueue) DeqN

func (p MemQueue) DeqN(n int) []interface{}

DeqN dequeue less than n in a batch

func (MemQueue) Enq

func (p MemQueue) Enq(data interface{}) error

Enq enqueue, return error if queue is full

func (MemQueue) EnqBlocking

func (p MemQueue) EnqBlocking(data interface{})

EnqBlocking enqueue, block if queue is full

func (MemQueue) Len

func (p MemQueue) Len() int

Len queue length

type PerfLog

type PerfLog struct {
	sync.Mutex
	// contains filtered or unexported fields
}

性能日志

func NewPerfLog

func NewPerfLog(maxMs uint32, logger *logrus.Entry) *PerfLog

生成PerfLog, maxMs 输出阈值,单位为毫秒

func (*PerfLog) Done

func (p *PerfLog) Done()

func (*PerfLog) Tick

func (p *PerfLog) Tick(label interface{})

type SyncMap

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

func (*SyncMap) Clear

func (p *SyncMap) Clear()

func (*SyncMap) Get

func (p *SyncMap) Get(key interface{}) (interface{}, bool)

func (*SyncMap) Keys

func (p *SyncMap) Keys() []interface{}

func (*SyncMap) Len

func (p *SyncMap) Len() int

func (*SyncMap) Put

func (p *SyncMap) Put(key, val interface{})

func (*SyncMap) Remove

func (p *SyncMap) Remove(key interface{})

type Throttle

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

func NewThrottle

func NewThrottle(max int) *Throttle

func (*Throttle) Acquire

func (p *Throttle) Acquire()

func (*Throttle) Available

func (p *Throttle) Available() int

func (*Throttle) Current

func (p *Throttle) Current() int

func (*Throttle) Release

func (p *Throttle) Release()

type Tick

type Tick int64

Tick unix timestamp in millisecond

func NewTick added in v1.2.2

func NewTick(t ...time.Time) Tick

NewTick create Tick. default value if now at local time

func (Tick) ToTime added in v1.2.2

func (p Tick) ToTime() time.Time

TickToTime convert tick to local time

type TimerCache

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

func NewTimerCache

func NewTimerCache(ttl int, expireCb func(key, value interface{})) *TimerCache

ttl in second expireCb, expire callback

func (*TimerCache) Get

func (p *TimerCache) Get(key interface{}) interface{}

func (*TimerCache) Keys

func (p *TimerCache) Keys() []interface{}

func (*TimerCache) Len

func (p *TimerCache) Len() int

func (*TimerCache) Put

func (p *TimerCache) Put(key, val interface{}) bool

func (*TimerCache) Remove

func (p *TimerCache) Remove(key interface{}) interface{}

func (*TimerCache) TTL added in v1.2.6

func (p *TimerCache) TTL(key interface{}) int64

TTL Check ttl (in second)

Jump to

Keyboard shortcuts

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