本文整理汇总了Golang中github.com/wandoulabs/redis-port/pkg/libs/errors.Trace函数的典型用法代码示例。如果您正苦于以下问题:Golang Trace函数的具体用法?Golang Trace怎么用?Golang Trace使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Trace函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: ping
func (c *conn) ping() error {
deadline := time.Now().Add(time.Second * 5)
if err := c.nc.SetDeadline(deadline); err != nil {
return errors.Trace(err)
}
if _, err := c.w.WriteString("*1\r\n$4\r\nping\r\n"); err != nil {
return errors.Trace(err)
}
if err := c.w.Flush(); err != nil {
return errors.Trace(err)
}
var rsp string
for !strings.HasSuffix(rsp, "\r\n") {
b := []byte{0}
if _, err := c.r.Read(b); err != nil {
return errors.Trace(err)
}
if len(rsp) == 0 && b[0] == '\n' {
continue
}
rsp += string(b)
}
rsp = rsp[:len(rsp)-2]
if strings.ToLower(rsp) != "+pong" {
return errors.Errorf("invalid response of command ping: %s", rsp)
} else {
return nil
}
}
示例2: EncodeObject
func (e *Encoder) EncodeObject(db uint32, key []byte, expireat uint64, obj interface{}) error {
o, ok := obj.(objectEncoder)
if !ok {
return errors.Errorf("unsupported object type")
}
if e.db == -1 || uint32(e.db) != db {
e.db = int64(db)
if err := e.enc.EncodeDatabase(int(db)); err != nil {
return errors.Trace(err)
}
}
if expireat != 0 {
if err := e.enc.EncodeExpiry(expireat); err != nil {
return errors.Trace(err)
}
}
if err := o.encodeType(e.enc); err != nil {
return err
}
if err := e.enc.EncodeString(key); err != nil {
return errors.Trace(err)
}
if err := o.encodeValue(e.enc); err != nil {
return err
}
return nil
}
示例3: loadRpdbRow
func loadRpdbRow(r rpdbReader, db uint32, key []byte) (rpdbRow, error) {
metaKey := EncodeMetaKey(db, key)
p, err := r.getRowValue(metaKey)
if err != nil || p == nil {
return nil, err
}
if len(p) == 0 {
return nil, errors.Trace(ErrObjectCode)
}
var o rpdbRow
var code = ObjectCode(p[0])
switch code {
default:
return nil, errors.Trace(ErrObjectCode)
case StringCode:
o = new(stringRow)
case HashCode:
o = new(hashRow)
case ListCode:
o = new(listRow)
case ZSetCode:
o = new(zsetRow)
case SetCode:
o = new(setRow)
}
o.lazyInit(&rpdbRowHelper{
code: code,
metaKey: metaKey,
dataKeyPrefix: EncodeDataKeyPrefix(db, key),
})
return o, o.ParseMetaValue(p)
}
示例4: encodeText
func (e *encoder) encodeText(s string) error {
if _, err := e.w.WriteString(s); err != nil {
return errors.Trace(err)
}
if _, err := e.w.WriteString("\r\n"); err != nil {
return errors.Trace(err)
}
return nil
}
示例5: encodeValue
func (o Set) encodeValue(enc *rdb.Encoder) error {
if err := enc.EncodeLength(uint32(len(o))); err != nil {
return errors.Trace(err)
}
for _, e := range o {
if err := enc.EncodeString(e); err != nil {
return errors.Trace(err)
}
}
return nil
}
示例6: decodeText
func (d *decoder) decodeText() (string, error) {
b, err := d.r.ReadBytes('\n')
if err != nil {
return "", errors.Trace(err)
}
if n := len(b) - 2; n < 0 || b[n] != '\r' {
return "", errors.Trace(ErrBadRespCRLFEnd)
} else {
return string(b[:n]), nil
}
}
示例7: writeSome
func (p *fileBuffer) writeSome(b []byte) (int, error) {
if p.f == nil {
return 0, errors.Trace(ErrClosedBacklog)
}
maxlen, offset := woffset(len(b), p.size, p.wpos)
if maxlen == 0 {
return 0, nil
}
n, err := p.f.WriteAt(b[:maxlen], int64(offset))
p.wpos += uint64(n)
return n, errors.Trace(err)
}
示例8: readSomeAt
func (p *memBuffer) readSomeAt(b []byte, rpos uint64) (int, error) {
if p.b == nil {
return 0, errors.Trace(ErrClosedBacklog)
}
if rpos > p.wpos || rpos+p.size < p.wpos {
return 0, errors.Trace(ErrInvalidOffset)
}
maxlen, offset := roffset(len(b), p.size, rpos, p.wpos)
if maxlen == 0 {
return 0, nil
}
n := copy(b, p.b[offset:offset+maxlen])
return n, nil
}
示例9: Clear
func (db *RocksDB) Clear() error {
if db.rkdb != nil {
db.rkdb.Close()
db.rkdb = nil
db.opts.SetCreateIfMissing(true)
db.opts.SetErrorIfExists(true)
if err := gorocks.DestroyDatabase(db.path, db.opts); err != nil {
return errors.Trace(err)
} else if db.rkdb, err = gorocks.Open(db.path, db.opts); err != nil {
return errors.Trace(err)
}
}
return nil
}
示例10: readSomeAt
func (p *fileBuffer) readSomeAt(b []byte, rpos uint64) (int, error) {
if p.f == nil {
return 0, errors.Trace(ErrClosedBacklog)
}
if rpos > p.wpos || rpos+p.size < p.wpos {
return 0, errors.Trace(ErrInvalidOffset)
}
maxlen, offset := roffset(len(b), p.size, rpos, p.wpos)
if maxlen == 0 {
return 0, nil
}
n, err := p.f.ReadAt(b[:maxlen], int64(offset))
return n, errors.Trace(err)
}
示例11: Serve
func Serve(config *Config, bl *rpdb.Rpdb) error {
h := &Handler{
config: config,
master: make(chan *conn, 0),
signal: make(chan int, 0),
}
defer func() {
close(h.signal)
}()
l, err := net.Listen("tcp", config.Listen)
if err != nil {
return errors.Trace(err)
}
defer l.Close()
if h.htable, err = redis.NewHandlerTable(h); err != nil {
return err
} else {
go h.daemonSyncMaster()
}
log.Infof("open listen address '%s' and start service", l.Addr())
for {
if nc, err := l.Accept(); err != nil {
return errors.Trace(err)
} else {
h.counters.clientsAccepted.Add(1)
go func() {
h.counters.clients.Add(1)
defer h.counters.clients.Sub(1)
c := newConn(nc, bl, h.config.ConnTimeout)
defer c.Close()
log.Infof("new connection: %s", c.summ)
if err := c.serve(h); err != nil {
if errors.Equal(err, io.EOF) {
log.Infof("connection lost: %s [io.EOF]", c.summ)
} else {
log.InfoErrorf(err, "connection lost: %s", c.summ)
}
} else {
log.Infof("connection exit: %s", c.summ)
}
}()
}
}
}
示例12: decodeRawBytes
func decodeRawBytes(r *BufReader, err error, refs ...interface{}) error {
if err != nil {
return err
}
if len(refs) == 0 {
if r.Len() != 0 {
return errors.Trace(ErrNotMatched)
}
return nil
}
for _, i := range refs {
switch x := i.(type) {
case byte:
if v, err := r.ReadByte(); err != nil {
return err
} else if v != x {
return errors.Errorf("read byte %d, expect %d", v, x)
}
case ObjectCode:
if v, err := r.ReadByte(); err != nil {
return err
} else if v != byte(x) {
return errors.Errorf("read code [%s], expect [%s]", ObjectCode(v), x)
}
case *[]byte:
p, err := r.ReadVarbytes()
if err != nil {
return err
}
*x = p
case *uint32:
v, err := r.ReadUvarint()
if err != nil {
return err
}
*x = uint32(v)
case *uint64:
v, err := r.ReadUvarint()
if err != nil {
return err
}
*x = v
case *int64:
v, err := r.ReadVarint()
if err != nil {
return err
}
*x = v
case *float64:
v, err := r.ReadFloat64()
if err != nil {
return err
}
*x = v
default:
log.Panicf("unsupported type in row value: %+v", x)
}
}
return nil
}
示例13: encodeBulkBytes
func (e *encoder) encodeBulkBytes(b []byte) error {
if b == nil {
return e.encodeInt(-1)
} else {
if err := e.encodeInt(int64(len(b))); err != nil {
return err
}
if _, err := e.w.Write(b); err != nil {
return errors.Trace(err)
}
if _, err := e.w.WriteString("\r\n"); err != nil {
return errors.Trace(err)
}
return nil
}
}
示例14: DecodeDump
func DecodeDump(p []byte) (interface{}, error) {
d := &decoder{}
if err := rdb.DecodeDump(p, 0, nil, 0, d); err != nil {
return nil, errors.Trace(err)
}
return d.obj, d.err
}
示例15: ParseFloat
func ParseFloat(i interface{}) (float64, error) {
var s string
switch x := Num64(i).(type) {
case int64:
return float64(x), nil
case uint64:
return float64(x), nil
case float64:
switch {
case math.IsNaN(x):
return 0, errors.New("float is NaN")
case math.IsInf(x, 0):
return 0, errors.New("float is Inf")
}
return float64(x), nil
case string:
s = x
case []byte:
s = string(x)
default:
s = fmt.Sprint(x)
}
f, err := strconv.ParseFloat(s, 64)
return f, errors.Trace(err)
}