-
Notifications
You must be signed in to change notification settings - Fork 23
/
client.go
74 lines (59 loc) · 1.85 KB
/
client.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
64
65
66
67
68
69
70
71
72
73
74
package costexplorer
import (
"github.com/aws/aws-sdk-go/aws/session"
SDK "github.com/aws/aws-sdk-go/service/costexplorer"
"github.com/evalphobia/aws-sdk-go-wrapper/config"
"github.com/evalphobia/aws-sdk-go-wrapper/log"
)
const (
serviceName = "CostExplorer"
)
// CostExplorer has *SDK.CostExplorer client.
type CostExplorer struct {
client *SDK.CostExplorer
logger log.Logger
}
// New returns initialized *CostExplorer.
func New(conf config.Config) (*CostExplorer, error) {
sess, err := conf.Session()
if err != nil {
return nil, err
}
return NewFromSession(sess), nil
}
// NewFromSession returns initialized *CostExplorer from aws.Session.
func NewFromSession(sess *session.Session) *CostExplorer {
return &CostExplorer{
client: SDK.New(sess),
logger: log.DefaultLogger,
}
}
// GetClient gets aws client.
func (svc *CostExplorer) GetClient() *SDK.CostExplorer {
return svc.client
}
// SetLogger sets logger.
func (svc *CostExplorer) SetLogger(logger log.Logger) {
svc.logger = logger
}
// GetCostAndUsage executes GetCostAndUsage operation with customized input.
func (svc *CostExplorer) GetCostAndUsage(input GetCostAndUsageInput) (UsageResult, error) {
return svc.DoGetCostAndUsage(input.ToInput())
}
// DoGetCostAndUsage executes GetCostAndUsage operation.
func (svc *CostExplorer) DoGetCostAndUsage(input *SDK.GetCostAndUsageInput) (UsageResult, error) {
output, err := svc.client.GetCostAndUsage(input)
if err != nil {
svc.Errorf("error on `GetCostAndUsage` operation; error=%w;", err)
return UsageResult{}, err
}
return NewUsageResult(output), nil
}
// Infof logging information.
func (svc *CostExplorer) Infof(format string, v ...interface{}) {
svc.logger.Infof(serviceName, format, v...)
}
// Errorf logging error information.
func (svc *CostExplorer) Errorf(format string, v ...interface{}) {
svc.logger.Errorf(serviceName, format, v...)
}