本文整理匯總了Golang中github.com/CodisLabs/redis-port/pkg/libs/errors.Errorf函數的典型用法代碼示例。如果您正苦於以下問題:Golang Errorf函數的具體用法?Golang Errorf怎麽用?Golang Errorf使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了Errorf函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: 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)
}
}
示例2: Header
func (l *Loader) Header() error {
header := make([]byte, 9)
if err := l.readFull(header); err != nil {
return err
}
if !bytes.Equal(header[:5], []byte("REDIS")) {
return errors.Errorf("verify magic string, invalid file format")
}
if version, err := strconv.ParseInt(string(header[5:]), 10, 64); err != nil {
return errors.Trace(err)
} else if version <= 0 || version > Version {
return errors.Errorf("verify version, invalid RDB version number %d", version)
}
return nil
}
示例3: readString
func (r *rdbReader) readString() ([]byte, error) {
length, encoded, err := r.readEncodedLength()
if err != nil {
return nil, err
}
if !encoded {
return r.readBytes(int(length))
}
switch t := uint8(length); t {
default:
return nil, errors.Errorf("invalid encoded-string %02x", t)
case rdbEncInt8:
i, err := r.readInt8()
return []byte(strconv.FormatInt(int64(i), 10)), err
case rdbEncInt16:
i, err := r.readInt16()
return []byte(strconv.FormatInt(int64(i), 10)), err
case rdbEncInt32:
i, err := r.readInt32()
return []byte(strconv.FormatInt(int64(i), 10)), err
case rdbEncLZF:
var inlen, outlen uint32
if inlen, err = r.readLength(); err != nil {
return nil, err
}
if outlen, err = r.readLength(); err != nil {
return nil, err
}
if in, err := r.readBytes(int(inlen)); err != nil {
return nil, err
} else {
return lzfDecompress(in, int(outlen))
}
}
}
示例4: encodeResp
func (e *encoder) encodeResp(r Resp) error {
switch x := r.(type) {
default:
return errors.Errorf("bad resp type <%s>", reflect.TypeOf(r))
case *String:
if err := e.encodeType(typeString); err != nil {
return err
}
return e.encodeText(x.Value)
case *Error:
if err := e.encodeType(typeError); err != nil {
return err
}
return e.encodeText(x.Value)
case *Int:
if err := e.encodeType(typeInt); err != nil {
return err
}
return e.encodeInt(x.Value)
case *BulkBytes:
if err := e.encodeType(typeBulkBytes); err != nil {
return err
}
return e.encodeBulkBytes(x.Value)
case *Array:
if err := e.encodeType(typeArray); err != nil {
return err
}
return e.encodeArray(x.Value)
}
}
示例5: 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
}
示例6: readLength
func (r *rdbReader) readLength() (uint32, error) {
length, encoded, err := r.readEncodedLength()
if err == nil && encoded {
err = errors.Errorf("encoded-length")
}
return length, err
}
示例7: readObjectValue
func (r *rdbReader) readObjectValue(t byte) ([]byte, error) {
var b bytes.Buffer
r = newRdbReader(io.TeeReader(r, &b))
switch t {
default:
return nil, errors.Errorf("unknown object-type %02x", t)
case rdbTypeHashZipmap:
fallthrough
case rdbTypeListZiplist:
fallthrough
case rdbTypeSetIntset:
fallthrough
case rdbTypeZSetZiplist:
fallthrough
case rdbTypeHashZiplist:
fallthrough
case rdbTypeString:
if _, err := r.readString(); err != nil {
return nil, err
}
case rdbTypeList, rdbTypeSet:
if n, err := r.readLength(); err != nil {
return nil, err
} else {
for i := 0; i < int(n); i++ {
if _, err := r.readString(); err != nil {
return nil, err
}
}
}
case rdbTypeZSet:
if n, err := r.readLength(); err != nil {
return nil, err
} else {
for i := 0; i < int(n); i++ {
if _, err := r.readString(); err != nil {
return nil, err
}
if _, err := r.readFloat(); err != nil {
return nil, err
}
}
}
case rdbTypeHash:
if n, err := r.readLength(); err != nil {
return nil, err
} else {
for i := 0; i < int(n); i++ {
if _, err := r.readString(); err != nil {
return nil, err
}
if _, err := r.readString(); err != nil {
return nil, err
}
}
}
}
return b.Bytes(), nil
}
示例8: Footer
func (l *Loader) Footer() error {
crc1 := l.crc.Sum64()
if crc2, err := l.readUint64(); err != nil {
return err
} else if crc1 != crc2 {
return errors.Errorf("checksum validation failed")
}
return nil
}
示例9: Dispatch
func (s *Server) Dispatch(arg0 interface{}, resp Resp) (Resp, error) {
if cmd, args, err := ParseArgs(resp); err != nil {
return nil, err
} else if f := s.t[cmd]; f == nil {
return nil, errors.Errorf("unknown command '%s'", cmd)
} else {
return f(arg0, args...)
}
}
示例10: initObject
func (d *decoder) initObject(obj interface{}) {
if d.err != nil {
return
}
if d.obj != nil {
d.err = errors.Errorf("invalid object, init again")
} else {
d.obj = obj
}
}
示例11: parseInt
func parseInt(s string, min, max int) (int, error) {
n, err := strconv.Atoi(s)
if err != nil {
return 0, err
}
if n >= min && n <= max {
return n, nil
}
return 0, errors.Errorf("out of range [%d,%d], got %d", min, max, n)
}
示例12: Sadd
func (d *decoder) Sadd(key, member []byte) {
if d.err != nil {
return
}
switch s := d.obj.(type) {
default:
d.err = errors.Errorf("invalid object, not a set")
case Set:
d.obj = append(s, member)
}
}
示例13: AsInt
func AsInt(r Resp, err error) (int64, error) {
if err != nil {
return 0, err
}
x, ok := r.(*Int)
if ok && x != nil {
return x.Value, nil
} else {
return 0, errors.Errorf("expect Int, but got <%s>", reflect.TypeOf(r))
}
}
示例14: AsBulkBytes
func AsBulkBytes(r Resp, err error) ([]byte, error) {
if err != nil {
return nil, err
}
x, ok := r.(*BulkBytes)
if ok && x != nil {
return x.Value, nil
} else {
return nil, errors.Errorf("expect BulkBytes, but got <%s>", reflect.TypeOf(r))
}
}
示例15: AsError
func AsError(r Resp, err error) (string, error) {
if err != nil {
return "", err
}
x, ok := r.(*Error)
if ok && x != nil {
return x.Value, nil
} else {
return "", errors.Errorf("expect Error, but got <%s>", reflect.TypeOf(r))
}
}