Passed
Pull Request — master (#8)
by eval
01:37 queued 10s
created

dynamodb/client_api_table.go   A

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
cc 5
eloc 17
dl 0
loc 31
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A dynamodb.*DynamoDB.DeleteTableFromName 0 5 1
A dynamodb.*DynamoDB.ExistTable 0 14 4
1
package dynamodb
2
3
import (
4
	"context"
5
6
	"github.com/evalphobia/aws-sdk-go-v2-wrapper/errors"
7
)
8
9
// DeleteTableFromName deletes a table of `name`.
10
func (svc *DynamoDB) DeleteTableFromName(ctx context.Context, name string) error {
11
	_, err := svc.DeleteTable(ctx, DeleteTableRequest{
12
		TableName: name,
13
	})
14
	return err
15
}
16
17
// ExistTable checks if the table already exists or not.
18
func (svc *DynamoDB) ExistTable(ctx context.Context, name string) (bool, error) {
19
	_, err := svc.DescribeTable(ctx, DescribeTableRequest{
20
		TableName: name,
21
	})
22
	if err == nil {
23
		return true, nil
24
	}
25
26
	if e, ok := err.(errors.ErrorData); ok {
27
		if e.GetAWSErrCode() == "ResourceNotFoundException" {
28
			return false, nil
29
		}
30
	}
31
	return false, err
32
}
33