本文整理汇总了Golang中github.com/tideland/golib/errors.IsError函数的典型用法代码示例。如果您正苦于以下问题:Golang IsError函数的具体用法?Golang IsError怎么用?Golang IsError使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了IsError函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: logCommand
// logCommand logs a command and its execution status.
func logCommand(cmd string, args []interface{}, err error, log bool) {
// Format the command for the log entry.
formatArgs := func() string {
if args == nil || len(args) == 0 {
return "(none)"
}
output := make([]string, len(args))
for i, arg := range args {
output[i] = string(valueToBytes(arg))
}
return strings.Join(output, " / ")
}
logOutput := func() string {
format := "CMD %s ARGS %s %s"
if err == nil {
return fmt.Sprintf(format, cmd, formatArgs(), "OK")
}
return fmt.Sprintf(format, cmd, formatArgs(), "ERROR "+err.Error())
}
// Log positive commands only if wanted, errors always.
if err != nil {
if errors.IsError(err, ErrServerResponse) || errors.IsError(err, ErrTimeout) {
return
}
logger.Errorf(logOutput())
} else if log {
logger.Infof(logOutput())
}
}
开发者ID:kung-foo,项目名称:golib,代码行数:30,代码来源:tools.go
示例2: TestIsError
// Test creation and checking.
func TestIsError(t *testing.T) {
assert := audit.NewTestingAssertion(t, true)
ec := 42
messages := errors.Messages{ec: "test error %d"}
err := errors.New(ec, messages, 1)
assert.ErrorMatch(err, `\[ERRORS_TEST:042\] test error 1`)
assert.True(errors.IsError(err, ec))
assert.False(errors.IsError(err, 0))
err = testError("test error 2")
assert.ErrorMatch(err, "test error 2")
assert.False(errors.IsError(err, ec))
assert.False(errors.IsError(err, 0))
}
开发者ID:jmptrader,项目名称:golib,代码行数:18,代码来源:errors_test.go
示例3: TestTransactionPipeline
func TestTransactionPipeline(t *testing.T) {
assert := audit.NewTestingAssertion(t, true)
conn, connRestore := connectDatabase(assert)
defer connRestore()
ppl, pplRestore := pipelineDatabase(assert)
defer pplRestore()
err := ppl.Do("multi")
assert.Nil(err)
ppl.Do("set", "tx:a", 1)
ppl.Do("set", "tx:b", 2)
ppl.Do("set", "tx:c", 3)
ppl.Do("exec")
results, err := ppl.Collect()
assert.Nil(err)
assert.Length(results, 5)
valueB, err := conn.DoInt("get", "tx:b")
assert.Nil(err)
assert.Equal(valueB, 2)
err = ppl.Do("multi")
assert.Nil(err)
ppl.Do("set", "tx:d", 4)
ppl.Do("set", "tx:e", 5)
ppl.Do("set", "tx:f", 6)
ppl.Do("discard")
results, err = ppl.Collect()
assert.Nil(err)
assert.Length(results, 5)
valueE, err := conn.DoValue("get", "tx:e")
assert.Nil(err)
assert.True(valueE.IsNil())
sig := make(chan struct{})
go func() {
<-sig
conn.Do("set", "tx:h", 99)
sig <- struct{}{}
}()
ppl.Do("watch", "tx:h")
err = ppl.Do("multi")
assert.Nil(err)
ppl.Do("set", "tx:g", 4)
ppl.Do("set", "tx:h", 5)
sig <- struct{}{}
ppl.Do("set", "tx:i", 6)
<-sig
ppl.Do("exec")
results, err = ppl.Collect()
assert.True(errors.IsError(err, redis.ErrTimeout))
valueH, err := conn.DoInt("get", "tx:h")
assert.Nil(err)
assert.Equal(valueH, 99)
}
开发者ID:kung-foo,项目名称:golib,代码行数:54,代码来源:commands_test.go
示例4: TestTransactionConnection
func TestTransactionConnection(t *testing.T) {
assert := audit.NewTestingAssertion(t, true)
conn, restore := connectDatabase(assert)
defer restore()
ok, err := conn.DoOK("multi")
assert.Nil(err)
assert.True(ok)
conn.Do("set", "tx:a", 1)
conn.Do("set", "tx:b", 2)
conn.Do("set", "tx:c", 3)
result, err := conn.Do("exec")
assert.Nil(err)
assert.Length(result, 3)
valueB, err := conn.DoInt("get", "tx:b")
assert.Nil(err)
assert.Equal(valueB, 2)
ok, err = conn.DoOK("multi")
assert.Nil(err)
assert.True(ok)
conn.Do("set", "tx:d", 4)
conn.Do("set", "tx:e", 5)
conn.Do("set", "tx:f", 6)
ok, err = conn.DoOK("discard")
assert.Nil(err)
assert.True(ok)
valueE, err := conn.DoValue("get", "tx:e")
assert.Nil(err)
assert.True(valueE.IsNil())
sig := make(chan struct{})
go func() {
asyncConn, restore := connectDatabase(assert)
defer restore()
<-sig
asyncConn.Do("set", "tx:h", 99)
sig <- struct{}{}
}()
conn.Do("watch", "tx:h")
ok, err = conn.DoOK("multi")
assert.Nil(err)
assert.True(ok)
conn.Do("set", "tx:g", 4)
conn.Do("set", "tx:h", 5)
sig <- struct{}{}
conn.Do("set", "tx:i", 6)
<-sig
_, err = conn.Do("exec")
assert.True(errors.IsError(err, redis.ErrTimeout))
valueH, err := conn.DoInt("get", "tx:h")
assert.Nil(err)
assert.Equal(valueH, 99)
}
开发者ID:kung-foo,项目名称:golib,代码行数:54,代码来源:commands_test.go
示例5: TestEnvironmentSubscribeUnsubscribe
// TestEnvironmentSubscribeUnsubscribe tests subscribing,
// checking and unsubscribing of cells.
func TestEnvironmentSubscribeUnsubscribe(t *testing.T) {
assert := audit.NewTestingAssertion(t, true)
env := cells.NewEnvironment("subscribe-unsubscribe")
defer env.Stop()
err := env.StartCell("foo", newCollectBehavior())
assert.Nil(err)
err = env.StartCell("bar", newCollectBehavior())
assert.Nil(err)
err = env.StartCell("baz", newCollectBehavior())
assert.Nil(err)
err = env.StartCell("yadda", newCollectBehavior())
assert.Nil(err)
err = env.Subscribe("humpf", "foo")
assert.True(errors.IsError(err, cells.ErrInvalidID))
err = env.Subscribe("foo", "humpf")
assert.True(errors.IsError(err, cells.ErrInvalidID))
err = env.Subscribe("foo", "bar", "baz")
assert.Nil(err)
subs, err := env.Subscribers("foo")
assert.Nil(err)
assert.Contents("bar", subs)
assert.Contents("baz", subs)
err = env.Unsubscribe("foo", "bar")
assert.Nil(err)
subs, err = env.Subscribers("foo")
assert.Nil(err)
assert.Contents("baz", subs)
err = env.Unsubscribe("foo", "baz")
assert.Nil(err)
subs, err = env.Subscribers("foo")
assert.Nil(err)
assert.Empty(subs)
}
开发者ID:reborn2005,项目名称:golib,代码行数:41,代码来源:cells_test.go
示例6: TestPubSub
func TestPubSub(t *testing.T) {
assert := audit.NewTestingAssertion(t, true)
conn, connRestore := connectDatabase(assert)
defer connRestore()
sub, subRestore := subscribeDatabase(assert)
defer subRestore()
_, err := conn.Do("subscribe", "pubsub")
assert.True(errors.IsError(err, redis.ErrUseSubscription))
err = sub.Subscribe("pubsub")
assert.Nil(err)
pv, err := sub.Pop()
assert.Nil(err)
assert.Equal(pv.Kind, "subscribe")
assert.Equal(pv.Channel, "pubsub")
assert.Equal(pv.Count, 1)
go func() {
for i := 0; i < 10; i++ {
time.Sleep(50 * time.Millisecond)
receivers, err := conn.DoInt("publish", "pubsub", i)
assert.Nil(err)
assert.Equal(receivers, 1)
}
}()
sleep := 1 * time.Millisecond
for i := 0; i < 10; i++ {
time.Sleep(sleep)
pv, err := sub.Pop()
assert.Nil(err)
assert.Equal(pv.Kind, "message")
assert.Equal(pv.Channel, "pubsub")
value, err := pv.Value.Int()
assert.Nil(err)
assert.Equal(value, i)
sleep *= 2
}
}
开发者ID:kung-foo,项目名称:golib,代码行数:40,代码来源:commands_test.go
示例7: TestEnvironmentStartStopCell
// TestEnvironmentStartStopCell tests starting, checking and
// stopping of cells.
func TestEnvironmentStartStopCell(t *testing.T) {
assert := audit.NewTestingAssertion(t, true)
env := cells.NewEnvironment("start-stop")
defer env.Stop()
err := env.StartCell("foo", newCollectBehavior())
assert.Nil(err)
hasFoo := env.HasCell("foo")
assert.True(hasFoo)
err = env.StopCell("foo")
assert.Nil(err)
hasFoo = env.HasCell("foo")
assert.False(hasFoo)
hasBar := env.HasCell("bar")
assert.False(hasBar)
err = env.StopCell("bar")
assert.True(errors.IsError(err, cells.ErrInvalidID))
hasBar = env.HasCell("bar")
assert.False(hasBar)
}
开发者ID:reborn2005,项目名称:golib,代码行数:26,代码来源:cells_test.go
示例8: IsCannotRecoverError
// IsCannotRecoverError checks if an error shows a cell that cannot
// recover.
func IsCannotRecoverError(err error) bool {
return errors.IsError(err, ErrCannotRecover)
}
开发者ID:tideland,项目名称:gocells,代码行数:5,代码来源:errors.go
示例9: IsCellInitError
// IsCellInitError checks if an error is a cell init error.
func IsCellInitError(err error) bool {
return errors.IsError(err, ErrCellInit)
}
开发者ID:tideland,项目名称:gocells,代码行数:4,代码来源:errors.go
示例10: IsValidationError
// IsValidationError checks if the error signals an invalid feed.
func IsValidationError(err error) bool {
return errors.IsError(err, ErrValidation)
}
开发者ID:kung-foo,项目名称:golib,代码行数:4,代码来源:errors.go
示例11: IsInvalidPathError
// IsInvalidPathError checks if a path cannot be found.
func IsInvalidPathError(err error) bool {
return errors.IsError(err, ErrInvalidPath)
}
开发者ID:tjyang,项目名称:golib,代码行数:4,代码来源:errors.go
示例12: IsNoTopicError
// IsNoTopicError checks if an error shows that an event has no topic..
func IsNoTopicError(err error) bool {
return errors.IsError(err, ErrNoTopic)
}
开发者ID:tideland,项目名称:gocells,代码行数:4,代码来源:errors.go
示例13: IsEventRecoveringError
// IsEventRecoveringError checks if an error is an error recovering error.
func IsEventRecoveringError(err error) bool {
return errors.IsError(err, ErrEventRecovering)
}
开发者ID:tideland,项目名称:gocells,代码行数:4,代码来源:errors.go
示例14: IsNoRequestError
// IsNoRequestError checks if an error signals that an event is no request.
func IsNoRequestError(err error) bool {
return errors.IsError(err, ErrNoRequest)
}
开发者ID:tideland,项目名称:gocells,代码行数:4,代码来源:errors.go
示例15: IsNegativeLinesError
// IsNegativeLinesError returns true, if the error shows the
// setting of a negative number of lines to start with.
func IsNegativeLinesError(err error) bool {
return errors.IsError(err, ErrNegativeLines)
}
开发者ID:kung-foo,项目名称:golib,代码行数:5,代码来源:errors.go
示例16: IsNoTargetError
// IsNoTargetError returns true, if the error signals that
// no target has been passed.
func IsNoTargetError(err error) bool {
return errors.IsError(err, ErrNoTarget)
}
开发者ID:kung-foo,项目名称:golib,代码行数:5,代码来源:errors.go
示例17: IsNoSourceError
// IsNoSourceError returns true, if the error signals that
// no source has been passed.
func IsNoSourceError(err error) bool {
return errors.IsError(err, ErrNoSource)
}
开发者ID:kung-foo,项目名称:golib,代码行数:5,代码来源:errors.go
示例18: IsNoPlainTextError
// IsNoPlainTextError checks if the error signals no plain content
// inside a text element.
func IsNoPlainTextError(err error) bool {
return errors.IsError(err, ErrNoPlainText)
}
开发者ID:kung-foo,项目名称:golib,代码行数:5,代码来源:errors.go
示例19: IsParsingError
// IsParsingError checks if the error signals a bad formatted value.
func IsParsingError(err error) bool {
return errors.IsError(err, ErrParsing)
}
开发者ID:kung-foo,项目名称:golib,代码行数:4,代码来源:errors.go
示例20: IsDuplicateIDError
// IsDuplicateIDError checks if an error is a cell already exists error.
func IsDuplicateIDError(err error) bool {
return errors.IsError(err, ErrDuplicateID)
}
开发者ID:tideland,项目名称:gocells,代码行数:4,代码来源:errors.go
注:本文中的github.com/tideland/golib/errors.IsError函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论