本文整理匯總了Golang中github.com/figoxu/utee.Chk函數的典型用法代碼示例。如果您正苦於以下問題:Golang Chk函數的具體用法?Golang Chk怎麽用?Golang Chk使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了Chk函數的12個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: NewFTtlQ
func NewFTtlQ(basePath, qname string) *FileTtlQ {
c := make(chan *qr.Qr, 1000000)
timerCache := utee.NewTimerCache(60, func(k, v interface{}) {
c <- v.(*qr.Qr)
})
d := fmt.Sprintf("%s/%s/%s", basePath, qname, "ldb")
log.Println("start @dbpath:", d)
err := os.MkdirAll(d, 0777)
utee.Chk(err)
db, err := leveldb.OpenFile(d, nil)
utee.Chk(err)
q := &FileTtlQ{
Ldb: db,
timerCache: timerCache,
basePath: basePath,
qname: qname,
shut_q: c,
}
closeQ := func(fq *qr.Qr) {
defer func() {
if err := recover(); err != nil {
log.Println(err, " (recover) @fq:", fq)
}
}()
fq.Close()
}
clean := func() {
for fq := range c {
closeQ(fq)
}
}
go clean()
return q
}
示例2: main
func main() {
b, err := deflate([]byte("hello world"))
utee.Chk(err)
log.Println(string(b))
rb, err := inflate(b)
utee.Chk(err)
log.Println(string(rb))
}
示例3: incHash
func incHash(pool *redis.Pool, id string, total, read, sent int) {
c := pool.Get()
defer c.Close()
_, err := c.Do("HINCRBY", id, "total", total)
utee.Chk(err)
_, err = c.Do("HINCRBY", id, "read", read)
utee.Chk(err)
_, err = c.Do("HINCRBY", id, "sent", sent)
utee.Chk(err)
}
示例4: saveHash
func saveHash(pool *redis.Pool, id string) {
c := pool.Get()
defer c.Close()
v, err := redis.Int(c.Do("EXISTS", id))
utee.Chk(err)
if v > 0 {
log.Println("already exist")
return
}
_, err = c.Do("HMSET", id, "total", 0, "read", 0, "send", 0)
utee.Chk(err)
c.Do("TTL", id, 60*60*2)
}
示例5: main
func main() {
m := make(map[string]string)
m["hello"] = "echo hello"
m["world"] = "echo world"
m["go"] = "echo go"
m["is"] = "echo is"
m["cool"] = "echo cool"
for k, v := range m {
log.Printf("k=%v, v=%v\n", k, v)
}
log.Println("---------------")
for k := range m {
log.Println(k)
}
bm = make(map[string]interface{})
bm["a"] = Info{
Made: "test",
Daily: 100,
}
b, e := json.Marshal(bm)
utee.Chk(e)
log.Println(string(b))
}
示例6: getHash
func getHash(pool *redis.Pool, id string) map[string]int {
c := pool.Get()
defer c.Close()
m, err := redis.IntMap(c.Do("HGETALL", id))
utee.Chk(err)
return m
}
示例7: insertBTest
func insertBTest() {
n := fmt.Sprint("figo", uuid.NewUUID().String())
s := &Student{
Id: bson.NewObjectId(),
Name: n,
VisitTimes: 10,
}
err := ds.DB(DB).C(C2).Insert(s)
utee.Chk(err)
}
示例8: getQ
func (p *FileTtlQ) getQ(uid interface{}) *qr.Qr {
qn := p.parseQName(uid)
v := p.timerCache.Get(uid)
if v == nil {
d := fmt.Sprintf("%s/%s/q/%s", p.basePath, p.qname, getOkDir(qn))
err := os.MkdirAll(d, 0777)
utee.Chk(err)
q, err := qr.New(
d,
qn,
qr.OptionBuffer(1000),
)
utee.Chk(err)
p.timerCache.Put(uid, q)
return q
}
q := v.(*qr.Qr)
return q
}
示例9: Handler
func Handler(w http.ResponseWriter, r *http.Request) {
dumx := Person{
Name: "zoro",
Age: 27,
Emails: []string{"[email protected]", "[email protected]"},
Company: "Omron",
Role: "SE"}
chxd := Person{Name: "chxd", Age: 27, Emails: []string{"[email protected]", "[email protected]"}}
onlineUser := OnlineUser{User: []*Person{&dumx, &chxd}}
//t := template.New("Person template")
//t, err := t.Parse(templ)
t, err := template.ParseFiles("/home/figo/develop/env/GOPATH/src/github.com/figoxu/goPraticse/template/tmpl.html")
utee.Chk(err)
err = t.Execute(w, onlineUser)
utee.Chk(err)
}
示例10: main
func main() {
fmt.Println("hello")
mg := connect("192.168.56.101/figoTest")
cp := mg.Copy()
defer cp.Close()
ds = mg
err := cp.DB(DB).C(C2).EnsureIndex(mgo.Index{Key: []string{"name"}, Unique: true})
utee.Chk(err)
A := func() {
insertATest()
}
B := func() {
insertBTest()
}
log.Println("insert with index 10000 times cost:", execute(B, 10000))
log.Println("insert without index 10000 times cost:", execute(A, 10000))
}
示例11: Enq
//ttl unit is second
func (p *FileTtlQ) Enq(uid interface{}, data []byte, ttl ...uint32) error {
q := p.getQ(uid)
k := string(uuid.NewUUID().String()) //16 byte
q.Enqueue(k)
t := int64(-1) //never ood (out of day)
if len(ttl) > 0 {
t = utee.TickSec() + int64(ttl[0])
}
qv := QValue{
Data: data,
Dod: t,
}
b, err := json.Marshal(qv)
utee.Chk(err)
p.Ldb.Put([]byte(k), b, nil)
return nil
}
示例12: connect
func connect(db_connection string) *mgo.Session {
session, err := mgo.Dial(db_connection)
utee.Chk(err)
return session
}