Skip to content

Commit

Permalink
[costexplorer] Add costexplorer.GetCostAndUsage (#49)
Browse files Browse the repository at this point in the history
  • Loading branch information
evalphobia authored Feb 14, 2020
1 parent 0e131ae commit b3e16ab
Show file tree
Hide file tree
Showing 5 changed files with 535 additions and 45 deletions.
45 changes: 23 additions & 22 deletions .gitignore
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
82 changes: 59 additions & 23 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,60 +33,96 @@ aws-sdk-go-wrapper
Simple wrapper for aws-sdk-go
At this time, it suports services below,

- [`DynamoDB`](https://github.com/evalphobia/aws-sdk-go-wrapper/tree/master/dynamodb)
- ListTables
- DescribeTable
- [`CloudWatch`](/cloudwatch)
- GetMetricStatistics
- [`CostExplorer`](/costexplorer)
- GetCostAndUsage
- [`DynamoDB`](/dynamodb)
- BatchWriteItem
- CreateTable
- UpdateTable
- DeleteItem
- DeleteTable
- Scan
- Query
- DescribeTable
- GetItem
- ListTables
- PutItem
- DeleteItem
- [`Kinesis`](https://github.com/evalphobia/aws-sdk-go-wrapper/tree/master/kinesis)
- DescribeStream
- Query
- UpdateTable
- Scan
- [`IAM`](/iam)
- GetGroup
- GetGroupPolicy
- GetPolicyVersion
- GetRolePolicy
- GetUserPolicy
- ListEntitiesForPolicy
- ListGroups
- ListGroupPolicies
- ListPolicies
- ListUsers
- ListUserPolicies
- ListRoles
- ListRolePolicies
- [`Kinesis`](/kinesis)
- CreateStream
- DeleteStream
- DescribeStream
- GetRecords
- GetShardIterator
- PutRecord
- [`KMS`](https://github.com/evalphobia/aws-sdk-go-wrapper/tree/master/kms)
- [`KMS`](/kms)
- CreateAlias
- CreateKey
- Decrypt
- DescribeKey
- Encrypt
- ReEncrypt
- ScheduleKeyDeletion
- [`Rekognition`](https://github.com/evalphobia/aws-sdk-go-wrapper/tree/master/rekognition)
- [`Pinpoint`](/pinpoint)
- SendEmail
- [`Rekognition`](/rekognition)
- CompareFaces
- CreateCollection
- DeleteCollection
- DeleteFaces
- DetectFaces
- DetectLabels
- DetectModerationLabels
- GetCelebrityInfo
- IndexFaces
- ListCollections
- ListFaces
- RecognizeCelebrities
- [`S3`](https://github.com/evalphobia/aws-sdk-go-wrapper/tree/master/s3)
- SearchFaces
- SearchFacesByImage
- [`S3`](/s3)
- CreateBucket
- DeleteBucket
- DeleteObject
- GetObject
- HeadObject
- PutObject
- DeleteObject
- [`SNS`](https://github.com/evalphobia/aws-sdk-go-wrapper/tree/master/sns)
- [`SNS`](/sns)
- CreatePlatformEndpoint
- CreateTopic
- DeleteTopic
- Subscribe
- Publish
- GetEndpointAttributes
- Publish
- SetEndpointAttributes
- [`SQS`](https://github.com/evalphobia/aws-sdk-go-wrapper/tree/master/sqs)
- GetQueueUrl
- Subscribe
- [`SQS`](/sqs)
- ChangeMessageVisibility
- CreateQueue
- DeleteQueue
- PurgeQueue
- SendMessageBatch
- ReceiveMessage
- DeleteMessage
- DeleteMessageBatch
- DeleteQueue
- GetQueueAttributes
- [`X-Ray`](https://github.com/evalphobia/aws-sdk-go-wrapper/tree/master/xray)
- GetQueueUrl
- ListQueues
- PurgeQueue
- ReceiveMessage
- SendMessageBatch
- [`X-Ray`](/xray)
- PutTraceSegments

# Quick Usage
Expand Down
64 changes: 64 additions & 0 deletions costexplorer/client.go
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...)
}
Loading

0 comments on commit b3e16ab

Please sign in to comment.