当前位置: 首页>>代码示例>>Golang>>正文


Golang errors.Errorf函数代码示例

本文整理汇总了Golang中github.com/timtadh/fs2/errors.Errorf函数的典型用法代码示例。如果您正苦于以下问题:Golang Errorf函数的具体用法?Golang Errorf怎么用?Golang Errorf使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了Errorf函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: Swap

func (l *List) Swap(i, j uint64) (err error) {
	if i >= l.count {
		return errors.Errorf("index, i, out of range")
	} else if j >= l.count {
		return errors.Errorf("index, j, out of range")
	}
	return l.blk(i, func(iIdx *idxBlk) (err error) {
		var ia uint64
		var I uint16 = uint16(i % itemsPerIdx)
		ia, err = iIdx.Get(I)
		if err != nil {
			return err
		}
		return l.blk(j, func(jIdx *idxBlk) (err error) {
			var ja uint64
			var J uint16 = uint16(j % itemsPerIdx)
			ja, err = jIdx.Get(J)
			if err != nil {
				return err
			}
			err = iIdx.Set(I, ja)
			if err != nil {
				return err
			}
			return jIdx.Set(J, ia)
		})
	})
}
开发者ID:postfix,项目名称:fs2,代码行数:28,代码来源:list.go

示例2: putKey

func (n *internal) putKey(v *Varchar, key []byte, put func(i int) error) (err error) {
	if n.keyCount()+1 >= int(n.meta.keyCap) {
		return errors.Errorf("Block is full.")
	}

	var i int
	var has bool
	if n.meta.flags&consts.VARCHAR_KEYS == 0 {
		i, has, err = find(v, n, key)
	} else {
		err = v.Do(*slice.AsUint64(&key), func(key []byte) (err error) {
			i, has, err = find(v, n, key)
			return err
		})
	}
	if err != nil {
		return err
	}

	if i < 0 {
		return errors.Errorf("find returned a negative int")
	} else if i >= int(n.meta.keyCap) {
		return errors.Errorf("find returned a int > than len(keys)")
	} else if has {
		return errors.Errorf(fmt.Sprintf("would have inserted a duplicate key, %v", key))
	}
	if err := n.putKeyAt(key, i); err != nil {
		return err
	}
	return put(i)
}
开发者ID:postfix,项目名称:fs2,代码行数:31,代码来源:internal.go

示例3: keyAt

/* returns the key at the address and index or an error
 */
func (self *BpTree) keyAt(a uint64, i int) (key []byte, err error) {
	err = self.do(
		a,
		func(n *internal) error {
			if i >= int(n.meta.keyCount) {
				return errors.Errorf("out of range")
			}
			return n.doKeyAt(self.varchar, i, func(k []byte) error {
				key = make([]byte, len(k))
				copy(key, k)
				return nil
			})
		},
		func(n *leaf) error {
			if i >= int(n.meta.keyCount) {
				return errors.Errorf("out of range")
			}
			return n.doKeyAt(self.varchar, i, func(k []byte) error {
				key = make([]byte, len(k))
				copy(key, k)
				return nil
			})
		},
	)
	if err != nil {
		return nil, err
	}
	return key, nil
}
开发者ID:postfix,项目名称:fs2,代码行数:31,代码来源:get.go

示例4: doFree

func (v *Varchar) doFree(a uint64, do func(*varFree) error) error {
	return v.do(
		a,
		func(*varCtrl) error { return errors.Errorf("unexpected ctrl blk") },
		do,
		func(*varRunMeta) error { return errors.Errorf("unexpected run blk") },
	)
}
开发者ID:postfix,项目名称:fs2,代码行数:8,代码来源:varchar.go

示例5: doCtrl

func (v *Varchar) doCtrl(do func(*varCtrl) error) error {
	return v.do(
		v.a,
		do,
		func(*varFree) error { return errors.Errorf("unexpected free blk") },
		func(*varRunMeta) error { return errors.Errorf("unexpected run blk") },
	)
}
开发者ID:postfix,项目名称:fs2,代码行数:8,代码来源:varchar.go

示例6: Remove

// Remove the underlying file. (must be already closed).
func (self *BlockFile) Remove() error {
	if self.opened {
		return errors.Errorf("Expected file to be closed")
	}
	if self.Path() == "" {
		return errors.Errorf("This was an anonymous map")
	}
	return os.Remove(self.Path())
}
开发者ID:postfix,项目名称:fs2,代码行数:10,代码来源:fmap.go

示例7: updateK

func (n *internal) updateK(v *Varchar, i int, key []byte) error {
	if i < 0 || i >= int(n.meta.keyCount) {
		return errors.Errorf("key is out of range")
	}
	if len(key) != int(n.meta.keySize) {
		return errors.Errorf("key was the wrong size")
	}
	idx, has, err := find(v, n, key)
	if err != nil {
		return err
	}
	if has && i != idx {
		log.Println(n.Debug(v))
		n.doKeyAt(v, idx, func(x []byte) error {
			k := n.key(idx)
			if v != nil {
				y, e := v.UnsafeGet(*slice.AsUint64(&k))
				log.Println(e)
				log.Println("key", x, y)
			} else {
				log.Println("key", x, "v was nil")
			}
			return nil
		})
		n.doKeyAt(v, i, func(x []byte) error {
			log.Println("replacing", x)
			return nil
		})
		return errors.Errorf("internal already had key %v, at %v, was going to put it at %v, replacing %v", key, idx, i, n.key(i))
	}
	oldk := make([]byte, len(n.key(i)))
	copy(oldk, n.key(i))
	flags := n.meta.flags
	if flags&consts.VARCHAR_KEYS != 0 {
		err := n.bigUpdateK(v, i, key)
		if err != nil {
			return err
		}
	} else {
		copy(n.key(i), key)
	}
	/*
		err = checkOrder(v, n)
		if err != nil {
			log.Println("replaced key", oldk)
			log.Println(n.Debug(v))
			return err
		}
	*/
	return nil
}
开发者ID:postfix,项目名称:fs2,代码行数:51,代码来源:internal.go

示例8: delKP

func (n *internal) delKP(v *Varchar, key []byte) error {
	i, has, err := find(v, n, key)
	if err != nil {
		return err
	}
	if !has {
		return errors.Errorf("key was not in the internal node")
	} else if i < 0 {
		return errors.Errorf("find returned a negative int")
	} else if i >= int(n.meta.keyCount) {
		return errors.Errorf("find returned a int > than len(keys)")
	}
	return n.delItemAt(v, i)
}
开发者ID:postfix,项目名称:fs2,代码行数:14,代码来源:internal.go

示例9: Pop

func (l *List) Pop() (item []byte, err error) {
	if l.count == 0 {
		return nil, errors.Errorf("Cannot pop an empty list")
	}
	var a uint64
	err = l.lastBlk(func(idx *idxBlk) (err error) {
		a, err = idx.Pop()
		return err
	})
	if err != nil {
		return nil, err
	}
	err = l.varchar.Do(a, func(data []byte) error {
		item = make([]byte, len(data))
		copy(item, data)
		return nil
	})
	if err != nil {
		return nil, err
	}
	err = l.varchar.Free(a)
	if err != nil {
		return nil, err
	}
	err = l.doCtrl(l.a, func(ctrl *ctrlBlk) error {
		ctrl.count--
		l.count = ctrl.count
		return nil
	})
	if err != nil {
		return nil, err
	}
	return item, nil
}
开发者ID:postfix,项目名称:fs2,代码行数:34,代码来源:list.go

示例10: balance

func (a *internal) balance(v *Varchar, b *internal) error {
	if b.meta.keyCount != 0 {
		return errors.Errorf("b was not empty")
	}
	m, err := a.balancePoint(v)
	if err != nil {
		return err
	}
	var lim int = int(a.meta.keyCount) - m
	for i := 0; i < lim; i++ {
		j := m + i
		copy(b.key(i), a.key(j))
		fmap.MemClr(a.key(j))
		*b.ptr(i) = *a.ptr(j)
		*a.ptr(j) = 0
	}
	b.meta.keyCount = a.meta.keyCount - uint16(m)
	a.meta.keyCount = uint16(m)
	/*
		err = checkOrder(v, a)
		if err != nil {
			log.Println("balance point", m)
			log.Println(a)
			return err
		}
		err = checkOrder(v, b)
		if err != nil {
			log.Println("balance point", m)
			log.Println(b)
			return err
		}
	*/
	return nil
}
开发者ID:postfix,项目名称:fs2,代码行数:34,代码来源:balance.go

示例11: Set

func (l *List) Set(i uint64, item []byte) (err error) {
	if i >= l.count {
		return errors.Errorf("index out of range")
	}
	var old_a uint64
	err = l.blk(i, func(idx *idxBlk) (err error) {
		old_a, err = idx.Get(uint16(i % itemsPerIdx))
		return err
	})
	if err != nil {
		return err
	}
	err = l.varchar.Free(old_a)
	if err != nil {
		return err
	}
	a, err := l.varchar.Alloc(len(item))
	if err != nil {
		return err
	}
	err = l.varchar.Do(a, func(data []byte) error {
		copy(data, item)
		return nil
	})
	if err != nil {
		return err
	}
	return l.blk(i, func(idx *idxBlk) (err error) {
		err = idx.Set(uint16(i%itemsPerIdx), a)
		if err != nil {
			return err
		}
		return
	})
}
开发者ID:postfix,项目名称:fs2,代码行数:35,代码来源:list.go

示例12: listRemove

func (v *Varchar) listRemove(node uint64, doNode nodeDoer) error {
	if node == 0 {
		return errors.Errorf("0 offset for node (the removed node)")
	}
	return doNode(node, func(n *listNode) (err error) {
		if n.prev != 0 {
			err = doNode(n.prev, func(pn *listNode) error {
				pn.next = n.next
				return nil
			})
			if err != nil {
				return nil
			}
		}
		if n.next != 0 {
			err = doNode(n.next, func(nn *listNode) error {
				nn.prev = n.prev
				return nil
			})
			if err != nil {
				return nil
			}
		}
		n.prev = 0
		n.next = 0
		return nil
	})
}
开发者ID:postfix,项目名称:fs2,代码行数:28,代码来源:varchar.go

示例13: listInsert

func (v *Varchar) listInsert(node, prev, next uint64, doNode nodeDoer) error {
	if node == 0 {
		return errors.Errorf("0 offset for node (the inserted node)")
	}
	return doNode(node, func(n *listNode) error {
		if prev == 0 && next == 0 {
			n.prev = 0
			n.next = 0
			return nil
		} else if next == 0 {
			return doNode(prev, func(pn *listNode) error {
				n.next = 0
				n.prev = prev
				pn.next = node
				return nil
			})
		} else if prev == 0 {
			return doNode(next, func(nn *listNode) error {
				n.next = next
				n.prev = 0
				nn.prev = node
				return nil
			})
		}
		return doNode(prev, func(pn *listNode) error {
			return doNode(next, func(nn *listNode) error {
				n.next = next
				n.prev = prev
				pn.next = node
				nn.prev = node
				return nil
			})
		})
	})
}
开发者ID:postfix,项目名称:fs2,代码行数:35,代码来源:varchar.go

示例14: Get

// Get the bytes at the offset and block count. You probably want to use
// Do instead. You must call Release() on the bytes when done.
func (self *BlockFile) Get(offset, blocks uint64) ([]byte, error) {
	if !self.opened {
		return nil, errors.Errorf("File is not open")
	}
	length := blocks * uint64(self.blksize)
	if (offset + length) > uint64(self.size) {
		return nil, errors.Errorf("Get outside of the file, (%d) %d + %d > %d", offset+length, offset, length, self.size)
	}
	self.outstanding += 1
	slice := &slice.Slice{
		Array: unsafe.Pointer(uintptr(self.mmap) + uintptr(offset)),
		Len:   int(length),
		Cap:   int(length),
	}
	return *slice.AsBytes(), nil
}
开发者ID:postfix,项目名称:fs2,代码行数:18,代码来源:fmap.go

示例15: UnsafeGet

func (v *Varchar) UnsafeGet(a uint64) (bytes []byte, err error) {
	rbytes, err := v.unsafeGet(a)
	if err != nil {
		return nil, err
	}
	m := asRunMeta(rbytes)
	fullLength := v.allocAmt(int(m.length))
	blks := uint64(v.blksNeeded(fullLength))
	offset, start, _ := v.startOffsetBlks(a)
	for offset+uint64(fullLength) >= blks*uint64(v.bf.BlockSize()) {
		blks++
	}
	size, err := v.bf.Size()
	if err != nil {
		return nil, err
	}
	for start+blks*uint64(v.bf.BlockSize()) > uint64(size) {
		blks--
	}
	allBytes, err := v.bf.Get(start, blks)
	if err != nil {
		return nil, err
	}
	err = v.bf.Release(allBytes)
	if err != nil {
		return nil, err
	}
	bytes = allBytes[offset:]
	flags := consts.AsFlag(bytes)
	if flags&consts.VARCHAR_RUN == 0 {
		return nil, errors.Errorf("bad address, was not a run block")
	}
	r := asRun(bytes)
	return r.bytes[:r.meta.length], nil
}
开发者ID:postfix,项目名称:fs2,代码行数:35,代码来源:varchar.go


注:本文中的github.com/timtadh/fs2/errors.Errorf函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。