本文整理匯總了Golang中github.com/reborndb/go/errors2.ErrorEqual函數的典型用法代碼示例。如果您正苦於以下問題:Golang ErrorEqual函數的具體用法?Golang ErrorEqual怎麽用?Golang ErrorEqual使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了ErrorEqual函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: TestWriteAfterWriterClose
func (s *testIoPipeSuite) TestWriteAfterWriterClose(c *C) {
r, w := Pipe()
ss := "hello"
errs := make(chan error)
go func() {
_, err := ioutils.WriteFull(w, []byte(ss))
c.Assert(err, IsNil)
c.Assert(w.Close(), IsNil)
_, err = w.Write([]byte("world"))
errs <- err
}()
buf := make([]byte, 4096)
n, err := ioutils.ReadFull(r, buf)
c.Assert(errors2.ErrorEqual(err, io.EOF), Equals, true)
c.Assert(string(buf[:n]), Equals, ss)
err = <-errs
c.Assert(errors2.ErrorEqual(err, io.ErrClosedPipe), Equals, true)
c.Assert(r.Close(), IsNil)
}
示例2: TestBytesizeError
func (s *testBytesizeSuite) TestBytesizeError(c *C) {
var err error
_, err = Parse("--1")
c.Assert(errors2.ErrorEqual(err, ErrBadBytesize), Equals, true)
_, err = Parse("hello world")
c.Assert(errors2.ErrorEqual(err, ErrBadBytesize), Equals, true)
_, err = Parse("123.132.32")
c.Assert(errors2.ErrorEqual(err, ErrBadBytesize), Equals, true)
}
示例3: Get
func (db *GoLevelDB) Get(key []byte) ([]byte, error) {
value, err := db.lvdb.Get(key, db.ropt)
if errors2.ErrorEqual(err, leveldb.ErrNotFound) {
return nil, nil
}
return value, errors.Trace(err)
}
示例4: run
func (h *Handler) run() error {
log.Infof("open listen address '%s' and start service", h.l.Addr())
for {
if nc, err := h.l.Accept(); err != nil {
return errors.Trace(err)
} else {
h.counters.clientsAccepted.Add(1)
go func() {
h.counters.clients.Add(1)
defer h.counters.clients.Sub(1)
c := newConn(nc, h, h.config.ConnTimeout)
log.Infof("new connection: %s", c)
if err := c.serve(h); err != nil {
if errors2.ErrorEqual(err, io.EOF) {
log.Infof("connection lost: %s [io.EOF]", c)
} else {
log.Warningf("connection lost: %s, err = %s", c, err)
}
} else {
log.Infof("connection exit: %s", c)
}
}()
}
}
return nil
}
示例5: TestPipeReadClose
func (s *testIoPipeSuite) TestPipeReadClose(c *C) {
for _, u := range pipeTests {
r, w := Pipe()
ch := make(chan int, 1)
if u.async {
go s.delayClose(c, w, ch, u)
} else {
s.delayClose(c, w, ch, u)
}
buf := make([]byte, 64)
n, err := r.Read(buf)
<-ch
expect := u.err
if expect == nil {
expect = io.EOF
}
c.Assert(errors2.ErrorEqual(err, expect), Equals, true)
c.Assert(n, Equals, 0)
c.Assert(r.Close(), IsNil)
}
}
示例6: testPipe2
func (s *testIoPipeSuite) testPipe2(c *C, fileName string) {
r, w := s.openPipe(c, fileName)
cc := 1024 * 128
ss := "Hello world!!"
go func() {
for i := 0; i < cc; i++ {
m := fmt.Sprintf("[%d]%s ", i, ss)
_, err := ioutils.WriteFull(w, []byte(m))
c.Assert(err, IsNil)
}
c.Assert(w.Close(), IsNil)
}()
time.Sleep(time.Millisecond * 100)
buf := make([]byte, len(ss)*cc*2)
n, err := ioutils.ReadFull(r, buf)
c.Assert(errors2.ErrorEqual(err, io.EOF), Equals, true)
buf = buf[:n]
for i := 0; i < cc; i++ {
m := fmt.Sprintf("[%d]%s ", i, ss)
c.Assert(len(buf) >= len(m), Equals, true)
c.Assert(string(buf[:len(m)]), Equals, m)
buf = buf[len(m):]
}
c.Assert(len(buf), Equals, 0)
c.Assert(r.Close(), IsNil)
}
示例7: Get
func (sp *Snapshot) Get(key []byte) ([]byte, error) {
value, err := sp.snap.Get(key, sp.ropt)
if errors2.ErrorEqual(err, leveldb.ErrNotFound) {
return nil, nil
}
return value, errors.Trace(err)
}
示例8: SetCmd
// SET key value [EX seconds] [PX milliseconds] [NX|XX]
func SetCmd(s Session, args [][]byte) (redis.Resp, error) {
if err := s.Store().Set(s.DB(), args); err != nil && errors2.ErrorNotEqual(err, store.ErrSetAborted) {
return toRespError(err)
} else if errors2.ErrorEqual(err, store.ErrSetAborted) {
return redis.NewBulkBytes(nil), nil
} else {
return redis.NewString("OK"), nil
}
}
示例9: TestPipeReadClose2
func (s *testIoPipeSuite) TestPipeReadClose2(c *C) {
r, w := Pipe()
ch := make(chan int, 1)
go s.delayClose(c, r, ch, pipeTest{})
n, err := r.Read(make([]byte, 64))
<-ch
c.Assert(errors2.ErrorEqual(err, io.ErrClosedPipe), Equals, true)
c.Assert(n, Equals, 0)
c.Assert(w.Close(), IsNil)
}
示例10: TestWriteNil
func (s *testIoPipeSuite) TestWriteNil(c *C) {
r, w := Pipe()
go func() {
_, err := w.Write(nil)
c.Assert(err, IsNil)
c.Assert(w.Close(), IsNil)
}()
buf := make([]byte, 4096)
n, err := ioutils.ReadFull(r, buf)
c.Assert(errors2.ErrorEqual(err, io.EOF), Equals, true)
c.Assert(n, Equals, 0)
c.Assert(r.Close(), IsNil)
}
示例11: testPipe3
func (s *testIoPipeSuite) testPipe3(c *C, fileName string) {
r, w := s.openPipe(c, fileName)
ch := make(chan int)
size := 4096
go func() {
buf := make([]byte, size)
for {
n, err := r.Read(buf)
if errors2.ErrorEqual(err, io.EOF) {
break
}
c.Assert(err, IsNil)
ch <- n
}
c.Assert(r.Close(), IsNil)
ch <- 0
}()
go func() {
buf := make([]byte, size)
for i := 1; i < size; i++ {
n, err := ioutils.WriteFull(w, buf[:i])
c.Assert(err, IsNil)
c.Assert(n, Equals, i)
}
c.Assert(w.Close(), IsNil)
}()
sum := 0
for i := 1; i < size; i++ {
sum += i
}
for {
n := <-ch
if n == 0 {
break
}
sum -= n
}
c.Assert(sum, Equals, 0)
}
示例12: testPipe4
func (s *testIoPipeSuite) testPipe4(c *C, fileName string) {
r, w := s.openPipe(c, fileName)
key := []byte("spinlock aes-128")
block := aes.BlockSize
count := 1024 * 1024 * 128 / block
go func() {
buf := make([]byte, count*block)
m, err := aes.NewCipher(key)
c.Assert(err, IsNil)
for i := 0; i < len(buf); i++ {
buf[i] = byte(i)
}
e := cipher.NewCBCEncrypter(m, make([]byte, block))
e.CryptBlocks(buf, buf)
n, err := ioutils.WriteFull(w, buf)
c.Assert(err, IsNil)
c.Assert(w.Close(), IsNil)
c.Assert(n, Equals, len(buf))
}()
buf := make([]byte, count*block)
m, err := aes.NewCipher(key)
c.Assert(err, IsNil)
_, err = ioutils.ReadFull(r, buf)
c.Assert(err, IsNil)
e := cipher.NewCBCDecrypter(m, make([]byte, block))
e.CryptBlocks(buf, buf)
for i := 0; i < len(buf); i++ {
// make gocheck faster
if buf[i] != byte(i) {
c.Assert(buf[i], Equals, byte(i))
}
}
_, err = ioutils.ReadFull(r, buf)
c.Assert(errors2.ErrorEqual(err, io.EOF), Equals, true)
c.Assert(r.Close(), IsNil)
}
示例13: testPipe1
func (s *testIoPipeSuite) testPipe1(c *C, fileName string) {
r, w := s.openPipe(c, fileName)
ss := "Hello world!!"
go func(data []byte) {
_, err := ioutils.WriteFull(w, data)
c.Assert(err, IsNil)
c.Assert(w.Close(), IsNil)
}([]byte(ss))
buf := make([]byte, 64)
n, err := ioutils.ReadFull(r, buf)
c.Assert(errors2.ErrorEqual(err, io.EOF), Equals, true)
c.Assert(n, Equals, len(ss))
c.Assert(string(buf[:n]), Equals, ss)
c.Assert(r.Close(), IsNil)
}
示例14: SetNX
// SETNX key value
func (s *Store) SetNX(db uint32, args [][]byte) (int64, error) {
if len(args) != 2 {
return 0, errArguments("len(args) = %d, expect = 2", len(args))
}
key := args[0]
value := args[1]
err := s.Set(db, [][]byte{key, value, []byte("NX")})
if err != nil {
// key exists
if errors2.ErrorEqual(err, ErrSetAborted) {
return 0, nil
} else {
return 0, err
}
}
return 1, nil
}
示例15: travelInLexRange
// travel zset in lex range, call f in every iteration.
func (o *zsetRow) travelInLexRange(s *Store, r *lexRangeSpec, f func(o *zsetRow) error) error {
it := s.getIterator()
defer s.putIterator(it)
o.Score = math.Inf(-1)
o.Member = r.Min
it.SeekTo(o.IndexKey())
prefixKey := o.IndexKeyPrefix()
for ; it.Valid(); it.Next() {
key := it.Key()
if !bytes.HasPrefix(key, prefixKey) {
return nil
}
key = key[len(prefixKey):]
if err := o.ParseIndexKeySuffix(key); err != nil {
return errors.Trace(err)
}
if r.InRange(o.Member) {
if err := f(o); errors2.ErrorEqual(err, errTravelBreak) {
return nil
} else if err != nil {
return errors.Trace(err)
}
} else if !r.LteMax(o.Member) {
return nil
}
}
if err := it.Error(); err != nil {
return errors.Trace(err)
}
return nil
}