-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[costexplorer] Add costexplorer.GetCostAndUsage (#49)
- Loading branch information
1 parent
0e131ae
commit b3e16ab
Showing
5 changed files
with
535 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,27 @@ | ||
# Compiled Object files, Static and Dynamic libs (Shared Objects) | ||
*.o | ||
*.a | ||
# Binaries for programs and plugins | ||
*.exe | ||
*.exe~ | ||
*.dll | ||
*.so | ||
*.dylib | ||
|
||
# Folders | ||
_obj | ||
_test | ||
vendor/bundle | ||
.local | ||
|
||
# Architecture specific extensions/prefixes | ||
*.[568vq] | ||
[568vq].out | ||
|
||
*.cgo1.go | ||
*.cgo2.c | ||
_cgo_defun.c | ||
_cgo_gotypes.go | ||
_cgo_export.* | ||
# Test binary, built with `go test -c` | ||
*.test | ||
|
||
_testmain.go | ||
# Output of the go coverage tool, specifically when used with LiteIDE | ||
*.out | ||
|
||
*.exe | ||
*.test | ||
*.prof | ||
# misc | ||
.DS_Store | ||
.DS_Store? | ||
._* | ||
.Spotlight-V100 | ||
.Trashes | ||
Icon? | ||
ehthumbs.db | ||
Thumbs.db | ||
*~ | ||
*.swp | ||
*.swo | ||
.vscode | ||
.idea |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
package costexplorer | ||
|
||
import ( | ||
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 | ||
} | ||
|
||
svc := &CostExplorer{ | ||
client: SDK.New(sess), | ||
logger: log.DefaultLogger, | ||
} | ||
return svc, nil | ||
} | ||
|
||
// 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...) | ||
} |
Oops, something went wrong.