utee

package module
v0.0.0-...-fbd61bd Latest Latest
Warning

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

Go to latest
Published: Feb 24, 2016 License: MIT Imports: 28 Imported by: 68

README

utee

utilities for golang

Documentation

Index

Constants

View Source
const (
	MAX_HTTP_CLIENT_CONCURRENT = 1000
)

Variables

View Source
var ErrFull = errors.New("queue is full")
View Source
var (
	HttpClientThrottle = make(chan interface{}, MAX_HTTP_CLIENT_CONCURRENT)
)
View Source
var (
	//passwd md5
	PlainMd5 = Md5Str("")
)

Functions

func Chk

func Chk(err error)

func Contains

func Contains(s []string, e string) bool

func ContainsInf

func ContainsInf(s []interface{}, e interface{}) bool

func ContainsObjectId

func ContainsObjectId(s []bson.ObjectId, e string) bool

func CreateRedisPool

func CreateRedisPool(size int, server, auth string) *redis.Pool

func DeleteMap

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

func Env

func Env(name string, required bool, showLog ...bool) string

func Fint

func Fint(s interface{}, dft ...int64) int

func Fint64

func Fint64(s interface{}, dft ...int64) int64

func Http2Get

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

func Http2Post

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

func HttpGet

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

func HttpPost

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

func IsPemExpire

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

func Md5

func Md5(b []byte) []byte

func Md5Str

func Md5Str(salt string) func(string) string

func MidConcurrent

func MidConcurrent(concurrent ...int) func(http.ResponseWriter, martini.Context)

func MidSlowLog

func MidSlowLog(limit int) func(*http.Request, martini.Context)

func MidTextDefault

func MidTextDefault(w http.ResponseWriter)

func MidWeb

func MidWeb(w http.ResponseWriter, c martini.Context)

func MongoConnect

func MongoConnect(db string) *mgo.Session

func MongoNotFound

func MongoNotFound(err error) bool

func NotFound

func NotFound(err error) bool

func ParseUrl

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

func SendMail

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

func Shuffle

func Shuffle(src []string) []string

func SplitSlice

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

split a into several parts, no more than n

func Tick

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

func TickHour

func TickHour() int64

func TickSec

func TickSec() int64

func ToTimeMillis

func ToTimeMillis(fmt string, timeStr string) (int64, error)

func Truncate

func Truncate(s string, n int) string

truncate string

func Unique

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

func UniqueStr

func UniqueStr(data []string) []string

Types

type J

type J map[string]interface{}

func F2j

func F2j(r *http.Request) J

parse form into J

type MemQueue

type MemQueue chan interface{}

func NewLeakMemQueue

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

create memory queue, auto-leak element concurrently to worker

func NewMemQueue

func NewMemQueue(cap int) MemQueue

func (MemQueue) Cap

func (p MemQueue) Cap() int

func (MemQueue) Deq

func (p MemQueue) Deq() interface{}

func (MemQueue) DeqN

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

dequeue less than n in a batch

func (MemQueue) Enq

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

enqueue, return error if queue is full

func (MemQueue) EnqBlocking

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

enqueue, block if queue is full

func (MemQueue) Len

func (p MemQueue) Len() int

type SimpleRedisQueue

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

func NewSimpleRedisQueue

func NewSimpleRedisQueue(server, auth, name string, concurrent, enqBatch, buffer int) *SimpleRedisQueue

redis queue with optional memory buffer server: redis server address auth: redis auth name: queue name in redis concurrent: concurrent number redis enqueue operation, must >=1 enqBatch: batch enqueue number, must >=1 buffer: memory buffer capacity, must >= 0

func (*SimpleRedisQueue) BufferCap

func (p *SimpleRedisQueue) BufferCap() int

func (*SimpleRedisQueue) BufferLen

func (p *SimpleRedisQueue) BufferLen() int

func (*SimpleRedisQueue) Deq

func (p *SimpleRedisQueue) Deq() (interface{}, error)

func (*SimpleRedisQueue) Enq

func (p *SimpleRedisQueue) Enq(data interface{}) error

enqueue, return error if buffer is full

func (*SimpleRedisQueue) EnqBlocking

func (p *SimpleRedisQueue) EnqBlocking(data interface{})

enqueue, block if buffer is full

func (*SimpleRedisQueue) Len

func (p *SimpleRedisQueue) Len() (int, error)

func (*SimpleRedisQueue) PollSize

func (p *SimpleRedisQueue) PollSize() int

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) 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 TimeMatrix

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

func (*TimeMatrix) Print

func (p *TimeMatrix) Print()

func (*TimeMatrix) Rec

func (p *TimeMatrix) Rec(name string)

type TimerCache

type TimerCache struct {
	sync.RWMutex
	// 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{}

type Web

type Web struct {
	W http.ResponseWriter
}

func (*Web) Json

func (p *Web) Json(code int, data interface{}) (int, string)

func (*Web) Txt

func (p *Web) Txt(code int, txt string) (int, string)

Jump to

Keyboard shortcuts

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