forked from awsdocs/aws-doc-sdk-examples
/
GetStatistics.go
63 lines (53 loc) · 2.01 KB
/
GetStatistics.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: MIT-0
// snippet-start:[ses.go.get_statistics]
package main
// snippet-start:[ses.go.get_statistics.imports]
import (
"fmt"
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/session"
"github.com/aws/aws-sdk-go/service/ses"
"github.com/aws/aws-sdk-go/service/ses/sesiface"
)
// snippet-end:[ses.go.get_statistics.imports]
// GetStatistics retrieves the send statistics for an Amazon SES service
// Inputs:
// svc is an Amazon SES service client
// Output:
// If success, statistics about the Amazon SES send operations and nil
// Otherwise, nil and an error from the call to GetSendStatistics
func GetStatistics(svc sesiface.SESAPI) (*ses.GetSendStatisticsOutput, error) {
// snippet-start:[ses.go.get_statistics.call]
result, err := svc.GetSendStatistics(nil)
// snippet-end:[ses.go.get_statistics.call]
return result, err
}
func main() {
// snippet-start:[ses.go.get_statistics.session]
sess := session.Must(session.NewSessionWithOptions(session.Options{
SharedConfigState: session.SharedConfigEnable,
}))
svc := ses.New(sess)
// snippet-end:[ses.go.get_statistics.session]
result, err := GetStatistics(svc)
if err != nil {
fmt.Println("Got an error retrieving SES send statistics")
fmt.Println(err)
return
}
// snippet-start:[ses.go.get_statistics.display]
dps := result.SendDataPoints
fmt.Println("Got", len(dps), "datapoints")
fmt.Println("")
for _, dp := range dps {
fmt.Println("Timestamp: ", dp.Timestamp)
fmt.Println("Attempts: ", aws.Int64Value(dp.DeliveryAttempts))
fmt.Println("Bounces: ", aws.Int64Value(dp.Bounces))
fmt.Println("Complaints:", aws.Int64Value(dp.Complaints))
fmt.Println("Rejects: ", aws.Int64Value(dp.Rejects))
fmt.Println("")
}
// snippet-end:[ses.go.get_statistics.display]
}
// snippet-end:[ses.go.get_statistics]