本文整理汇总了Golang中github.com/left2right/redis-port/pkg/libs/errors.Trace函数的典型用法代码示例。如果您正苦于以下问题:Golang Trace函数的具体用法?Golang Trace怎么用?Golang Trace使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Trace函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: 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
}
示例2: 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
}
示例3: 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
}
}
示例4: 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
}
示例5: writeSome
func (p *fileBuffer) writeSome(b []byte) (int, error) {
if p.f == nil {
return 0, errors.Trace(io.ErrClosedPipe)
}
maxlen, offset := woffset(len(b), p.size, p.rpos, 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)
}
示例6: decodeType
func (d *decoder) decodeType() (respType, error) {
if b, err := d.r.ReadByte(); err != nil {
return 0, errors.Trace(err)
} else {
return respType(b), nil
}
}
示例7: 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
}
示例8: authPassword
func authPassword(c net.Conn, passwd string) {
if passwd == "" {
return
}
_, err := c.Write(redis.MustEncodeToBytes(redis.NewCommand("auth", passwd)))
if err != nil {
log.PanicError(errors.Trace(err), "write auth command failed")
}
var b = make([]byte, 5)
if _, err := io.ReadFull(c, b); err != nil {
log.PanicError(errors.Trace(err), "read auth response failed")
}
if strings.ToUpper(string(b)) != "+OK\r\n" {
log.Panic("auth failed")
}
}
示例9: openSyncConn
func openSyncConn(target string, passwd string) (net.Conn, <-chan int64) {
c := openNetConn(target, passwd)
if _, err := c.Write(redis.MustEncodeToBytes(redis.NewCommand("sync"))); err != nil {
log.PanicError(errors.Trace(err), "write sync command failed")
}
return c, waitRdbDump(c)
}
示例10: 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
}
}
示例11: rclose
func (p *fileBuffer) rclose() error {
if f := p.f; f != nil {
p.f = nil
defer f.Close()
return errors.Trace(f.Truncate(0))
}
return nil
}
示例12: Parse
func Parse(s string) (int64, error) {
if !BytesizeRegexp.MatchString(s) {
return 0, errors.Trace(ErrBadBytesize)
}
subs := BytesizeRegexp.FindStringSubmatch(s)
if len(subs) != 3 {
return 0, errors.Trace(ErrBadBytesize)
}
size := int64(0)
switch strings.ToUpper(string(subs[2])) {
case "B", "":
size = 1
case "KB", "K":
size = KB
case "MB", "M":
size = MB
case "GB", "G":
size = GB
case "TB", "T":
size = TB
case "PB", "P":
size = PB
default:
return 0, errors.Trace(ErrBadBytesizeUnit)
}
text := subs[1]
if digitsRegexp.MatchString(text) {
n, err := strconv.ParseInt(text, 10, 64)
if err != nil {
return 0, errors.Trace(ErrBadBytesize)
}
size *= n
} else {
n, err := strconv.ParseFloat(text, 64)
if err != nil {
return 0, errors.Trace(ErrBadBytesize)
}
size = int64(float64(size) * n)
}
return size, nil
}
示例13: Encode
func Encode(w *bufio.Writer, r Resp, flush bool) error {
e := &encoder{w}
if err := e.encodeResp(r); err != nil {
return err
}
if !flush {
return nil
}
return errors.Trace(w.Flush())
}
示例14: decodeBulkBytes
func (d *decoder) decodeBulkBytes() ([]byte, error) {
n, err := d.decodeInt()
if err != nil {
return nil, err
}
if n < -1 {
return nil, errors.Trace(ErrBadRespBytesLen)
} else if n == -1 {
return nil, nil
}
b := make([]byte, n+2)
if _, err := io.ReadFull(d.r, b); err != nil {
return nil, errors.Trace(err)
}
if b[n] != '\r' || b[n+1] != '\n' {
return nil, errors.Trace(ErrBadRespCRLFEnd)
}
return b[:n], nil
}
示例15: readSome
func (p *fileBuffer) readSome(b []byte) (int, error) {
if p.f == nil {
return 0, errors.Trace(io.ErrClosedPipe)
}
maxlen, offset := roffset(len(b), p.size, p.rpos, p.wpos)
if maxlen == 0 {
return 0, nil
}
n, err := p.f.ReadAt(b[:maxlen], int64(offset))
p.rpos += uint64(n)
if p.rpos == p.wpos {
p.rpos = 0
p.wpos = 0
if err == nil {
err = p.f.Truncate(0)
}
}
return n, errors.Trace(err)
}