英文:
Reading CloudWatch log query status in go SDK v2
问题
我正在使用Go的v2 SDK运行一个CloudWatch日志查询。我已经成功使用StartQuery方法提交了查询,但是我似乎无法处理结果。
我将查询ID存储在一个变量中(queryID),并使用以下方式调用GetQueryResults方法:
results, err := svc.GetQueryResults(context.TODO(), &cloudwatchlogs.GetQueryResultsInput{QueryId: queryId})
我该如何读取内容?具体来说,我想查看Status字段。如果我在命令行中运行查询,这个字段会返回一个字符串描述。根据SDK文档,这是一个自定义类型"QueryStatus",它被定义为一个带有枚举常量的字符串。
我尝试将其与常量名称进行比较,例如:
if results.Status == cloudwatchlogs.GetQueryResultsOutput.QueryStatus.QueryStatusComplete
但是编译器不接受这样的写法。我该如何引用这些常量或者获取字符串值本身?
英文:
I'm running a CloudWatch log query through the v2 SDK for Go. I've successfully submitted the query using the StartQuery method, however I can't seem to process the results.
I've got my query ID in a variable (queryID) and am using the GetQueryResults method as follows:
results, err := svc.GetQueryResults(context.TODO(), &cloudwatchlogs.GetQueryResultsInput{QueryId: queryId,})
How do I actually read the contents? Specifically, I'm looking at the Status field. If I run the query at the command line, this comes back as a string description. According to the SDK docs, this is a bespoke type "QueryStatus", which is defined as a string with enumerated constants.
I've tried comparing to the constant names, e.g.
if results.Status == cloudwatchlogs.GetQueryResultsOutput.QueryStatus.QueryStatusComplete
but the compiler doesn't accept this. How do I either reference the constants or get to the string value itself?
答案1
得分: 1
QueryStatus
类型在 单独的 types 包中 进行了定义。Go SDK 的服务都是按照这种方式组织的。
import "github.com/aws/aws-sdk-go-v2/service/cloudwatchlogs/types"
if res.Status == types.QueryStatusComplete {
fmt.Println("complete!")
}
英文:
The QueryStatus
type is defined in the separate types package. The Go SDK services are all organised this way.
import "github.com/aws/aws-sdk-go-v2/service/cloudwatchlogs/types"
if res.Status == types.QueryStatusComplete {
fmt.Println("complete!")
}
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论