如何在Go中模拟对DynamoDB的错误?

huangapple go评论95阅读模式
英文:

How to simulate errors against DynamoDB in Go?

问题

如何使用Go模拟对DynamoDB的错误?这篇博文只讲了Java的方法... https://aws.amazon.com/blogs/developer/injecting-failures-and-latency-using-the-aws-sdk-for-java/

英文:

How does one simulate errors against DynamoDB using Go? This blog post only talks about Java... https://aws.amazon.com/blogs/developer/injecting-failures-and-latency-using-the-aws-sdk-for-java/

答案1

得分: 3

import (
   errors "golang.org/x/xerrors"
)

client := dynamodb.New(sess)
client.Handlers.Validate.AfterEachFn = func(item request.HandlerListRunItem) bool {
	item.Request.Error = errors.New("模拟错误")
	return false
}
英文:
import (
   errors "golang.org/x/xerrors"
)

client := dynamodb.New(sess)
client.Handlers.Validate.AfterEachFn = func(item request.HandlerListRunItem) bool {
	item.Request.Error = errors.New("simulated error")
	return false
}

huangapple
  • 本文由 发表于 2021年12月16日 08:57:53
  • 转载请务必保留本文链接:https://go.coder-hub.com/70372096.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定