本文整理匯總了Golang中github.com/CodisLabs/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: 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
}
示例4: 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
}
}
示例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: 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
}
示例7: 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)
}
示例8: 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
}
}
示例9: ParseFloat64
func ParseFloat64(i interface{}) (float64, error) {
if v, ok := Num64(i); ok {
switch x := v.(type) {
case int64:
return float64(x), nil
case uint64:
return float64(x), nil
case float64:
switch {
case math.IsNaN(x):
return 0, errors.Errorf("parse nan float64")
case math.IsInf(x, 0):
return 0, errors.Errorf("parse inf float64")
}
return float64(x), nil
default:
return 0, errors.Errorf("parse float64 from unknown num64")
}
} else {
var s string
switch x := i.(type) {
case nil:
return 0, errors.Errorf("parse float64 from nil")
case string:
s = x
case []byte:
s = string(x)
default:
return 0, errors.Errorf("parse float64 from <%s>", reflect.TypeOf(i))
}
f, err := strconv.ParseFloat(s, 64)
return f, errors.Trace(err)
}
}
示例10: 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")
}
}
示例11: 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)
}
示例12: 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
}
}
示例13: 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
}
示例14: 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
}
示例15: 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
}