[英]Reading CloudWatch log query status in go SDK v2
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.我正在通过 v2 SDK 为 Go 运行 CloudWatch 日志查询。我已经使用 StartQuery 方法成功提交了查询,但是我似乎无法处理结果。
I've got my query ID in a variable (queryID) and am using the GetQueryResults method as follows:我在变量 (queryID) 中获取了我的查询 ID,并且正在使用 GetQueryResults 方法,如下所示:
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.
具体来说,我正在查看 Status 字段。 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 .
根据 SDK 文档,这是一个定制类型“QueryStatus”,它被定义为一个带有枚举常量的字符串。
I've tried comparing to the constant names, eg我试过与常量名称进行比较,例如
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?
我如何引用常量或获取字符串值本身?
The QueryStatus
type is defined in the separate types package . QueryStatus
类型在单独的类型 package中定义。 The Go SDK services are all organised this way. Go SDK 服务都是这样组织的。
import "github.com/aws/aws-sdk-go-v2/service/cloudwatchlogs/types"
if res.Status == types.QueryStatusComplete {
fmt.Println("complete!")
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.