本文整理汇总了Golang中github.com/wandoulabs/redis-port/pkg/libs/errors.Errorf函数的典型用法代码示例。如果您正苦于以下问题:Golang Errorf函数的具体用法?Golang Errorf怎么用?Golang Errorf使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Errorf函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: getMembers
func (o *setRow) getMembers(r rpdbReader, count int64) ([][]byte, error) {
it := r.getIterator()
defer r.putIterator(it)
var members [][]byte
for pfx := it.SeekTo(o.DataKeyPrefix()); count > 0 && it.Valid(); it.Next() {
key := it.Key()
if !bytes.HasPrefix(key, pfx) {
break
}
sfx := key[len(pfx):]
if err := o.ParseDataKeySuffix(sfx); err != nil {
return nil, err
}
if err := o.ParseDataValue(it.Value()); err != nil {
return nil, err
}
if len(o.Member) == 0 {
return nil, errors.Errorf("len(member) = %d", len(o.Member))
}
members = append(members, o.Member)
count--
}
if err := it.Error(); err != nil {
return nil, err
}
if len(members) == 0 {
return nil, errors.Errorf("len(members) = %d, set.size = %d", len(members), o.Size)
}
return members, nil
}
开发者ID:fengshao0907,项目名称:rpdb,代码行数:30,代码来源:set.go
示例2: getAllValues
func (o *hashRow) getAllValues(r rpdbReader) ([][]byte, error) {
it := r.getIterator()
defer r.putIterator(it)
var values [][]byte
for pfx := it.SeekTo(o.DataKeyPrefix()); it.Valid(); it.Next() {
key := it.Key()
if !bytes.HasPrefix(key, pfx) {
break
}
if err := o.ParseDataValue(it.Value()); err != nil {
return nil, err
}
if len(o.Value) == 0 {
return nil, errors.Errorf("len(value) = %d", len(o.Value))
}
values = append(values, o.Value)
}
if err := it.Error(); err != nil {
return nil, err
}
if len(values) == 0 || int64(len(values)) != o.Size {
return nil, errors.Errorf("len(values) = %d, hash.size = %d", len(values), o.Size)
}
return values, nil
}
开发者ID:fengshao0907,项目名称:rpdb,代码行数:25,代码来源:hash.go
示例3: 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)
}
}
开发者ID:TigerZhang,项目名称:redis-port,代码行数:34,代码来源:strconv.go
示例4: 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
}
开发者ID:fengshao0907,项目名称:rpdb,代码行数:60,代码来源:row.go
示例5: getAllFields
func (o *hashRow) getAllFields(r rpdbReader) ([][]byte, error) {
it := r.getIterator()
defer r.putIterator(it)
var fields [][]byte
for pfx := it.SeekTo(o.DataKeyPrefix()); it.Valid(); it.Next() {
key := it.Key()
if !bytes.HasPrefix(key, pfx) {
break
}
sfx := key[len(pfx):]
if err := o.ParseDataKeySuffix(sfx); err != nil {
return nil, err
}
if len(o.Field) == 0 {
return nil, errors.Errorf("len(field) = %d", len(o.Field))
}
fields = append(fields, o.Field)
}
if err := it.Error(); err != nil {
return nil, err
}
if len(fields) == 0 || int64(len(fields)) != o.Size {
return nil, errors.Errorf("len(fields) = %d, hash.size = %d", len(fields), o.Size)
}
return fields, nil
}
开发者ID:fengshao0907,项目名称:rpdb,代码行数:26,代码来源:hash.go
示例6: parseArgument
func parseArgument(arg interface{}, ref interface{}) error {
switch x := ref.(type) {
default:
return errors.Errorf("unsupported type, %v", reflect.TypeOf(x))
case *int64:
v, err := ParseInt(arg)
if err != nil {
return errors.Errorf("expect %v, %s", reflect.TypeOf(*x), err.Error())
}
*x = v
case *uint32:
v, err := ParseUint(arg)
if err != nil {
return errors.Errorf("expect %v, %s", reflect.TypeOf(*x), err.Error())
} else if v > math.MaxUint32 {
return errors.Errorf("expect %v, but got %d", reflect.TypeOf(*x), v)
}
*x = uint32(v)
case *uint64:
v, err := ParseUint(arg)
if err != nil {
return errors.Errorf("expect %v, %s", reflect.TypeOf(*x), err.Error())
}
*x = v
case *float64:
v, err := ParseFloat(arg)
if err != nil {
return errors.Errorf("expect %v, %s", reflect.TypeOf(*x), err.Error())
}
*x = v
case *[]byte:
switch y := arg.(type) {
case []byte:
*x = y
case string:
*x = []byte(y)
default:
return errors.Errorf("expect %v, but got %v", reflect.TypeOf(*x), reflect.TypeOf(y))
}
if len(*x) == 0 {
return errors.Errorf("byte slice length = 0")
}
case *string:
switch y := arg.(type) {
case []byte:
*x = string(y)
case string:
*x = y
default:
return errors.Errorf("expect %v, but got %v", reflect.TypeOf(*x), reflect.TypeOf(y))
}
if len(*x) == 0 {
return errors.Errorf("string length = 0")
}
}
return nil
}
开发者ID:fengshao0907,项目名称:rpdb,代码行数:57,代码来源:format.go
示例7: 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
}
开发者ID:TigerZhang,项目名称:redis-port,代码行数:15,代码来源:loader.go
示例8: loadObjectValue
func (o *setRow) loadObjectValue(r rpdbReader) (interface{}, error) {
it := r.getIterator()
defer r.putIterator(it)
set := make([][]byte, 0, o.Size)
for pfx := it.SeekTo(o.DataKeyPrefix()); it.Valid(); it.Next() {
key := it.Key()
if !bytes.HasPrefix(key, pfx) {
break
}
sfx := key[len(pfx):]
if err := o.ParseDataKeySuffix(sfx); err != nil {
return nil, err
}
if err := o.ParseDataValue(it.Value()); err != nil {
return nil, err
}
set = append(set, o.Member)
}
if err := it.Error(); err != nil {
return nil, err
}
if o.Size == 0 || int64(len(set)) != o.Size {
return nil, errors.Errorf("len(set) = %d, set.size = %d", len(set), o.Size)
}
return rdb.Set(set), nil
}
开发者ID:fengshao0907,项目名称:rpdb,代码行数:26,代码来源:set.go
示例9: DoMustOK
func (c *conn) DoMustOK(cmd *redis.Array, timeout time.Duration) error {
if rsp, err := c.Do(cmd, timeout); err != nil {
return err
} else {
s, ok := rsp.(*redis.String)
if ok {
if s.Value == "OK" {
return nil
}
c.err = errors.Errorf("not OK, got %s", s.Value)
} else {
c.err = errors.Errorf("not string response, got %v", rsp.Type())
}
return c.err
}
}
开发者ID:fengshao0907,项目名称:rpdb,代码行数:16,代码来源:migrate.go
示例10: 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
}
开发者ID:hushi55,项目名称:Grep,代码行数:27,代码来源:encoder.go
示例11: 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)
}
}
开发者ID:TigerZhang,项目名称:redis-port,代码行数:31,代码来源:encoder.go
示例12: 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))
}
}
}
开发者ID:hushi55,项目名称:Grep,代码行数:35,代码来源:reader.go
示例13: loadObjectValue
func (o *hashRow) loadObjectValue(r rpdbReader) (interface{}, error) {
it := r.getIterator()
defer r.putIterator(it)
hash := make([]*rdb.HashElement, 0, o.Size)
for pfx := it.SeekTo(o.DataKeyPrefix()); it.Valid(); it.Next() {
key := it.Key()
if !bytes.HasPrefix(key, pfx) {
break
}
sfx := key[len(pfx):]
if err := o.ParseDataKeySuffix(sfx); err != nil {
return nil, err
}
if err := o.ParseDataValue(it.Value()); err != nil {
return nil, err
}
hash = append(hash, &rdb.HashElement{Field: o.Field, Value: o.Value})
}
if err := it.Error(); err != nil {
return nil, err
}
if o.Size == 0 || int64(len(hash)) != o.Size {
return nil, errors.Errorf("len(hash) = %d, hash.size = %d", len(hash), o.Size)
}
return rdb.Hash(hash), nil
}
开发者ID:fengshao0907,项目名称:rpdb,代码行数:26,代码来源:hash.go
示例14: 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
}
}
开发者ID:fengshao0907,项目名称:rpdb,代码行数:30,代码来源:conn.go
示例15: readLength
func (r *rdbReader) readLength() (uint32, error) {
length, encoded, err := r.readEncodedLength()
if err == nil && encoded {
err = errors.Errorf("encoded-length")
}
return length, err
}
开发者ID:hushi55,项目名称:Grep,代码行数:7,代码来源:reader.go
示例16: 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
}
开发者ID:hushi55,项目名称:Grep,代码行数:59,代码来源:reader.go
示例17: 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
}
开发者ID:TigerZhang,项目名称:redis-port,代码行数:9,代码来源:loader.go
示例18: 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...)
}
}
开发者ID:TigerZhang,项目名称:redis-port,代码行数:9,代码来源:server.go
示例19: 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
}
}
开发者ID:hushi55,项目名称:Grep,代码行数:10,代码来源:decoder.go
示例20: 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)
}
开发者ID:fysoft2006,项目名称:redis-port,代码行数:10,代码来源:main.go
注:本文中的github.com/wandoulabs/redis-port/pkg/libs/errors.Errorf函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论