/
DBClusters.go
44 lines (34 loc) · 1.05 KB
/
DBClusters.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
package aws
import (
"context"
"errors"
"github.com/aws/aws-sdk-go-v2/service/rds"
"github.com/aws/aws-sdk-go-v2/service/rds/types"
)
type DBClusters []types.DBCluster
func NewDBClusters(c *rds.Client) (DBClusters, error) {
ctx := context.Background()
input := &rds.DescribeDBClustersInput{}
output, err := c.DescribeDBClusters(ctx, input)
if err != nil {
return nil, err
}
return output.DBClusters, nil
}
// GetDBClusterNamesはクラスタ名のスライスを返します。
func (d *DBClusters) GetDBClusterNames() []string {
DBClusterNames := []string{}
for _, dbcluster := range *d {
DBClusterNames = append(DBClusterNames, *dbcluster.DBClusterIdentifier)
}
return DBClusterNames
}
// クラスタ名からそのクラスタの詳細情報を返します。
func (d *DBClusters) GetDBClusterInfoFromName(name *string) (types.DBCluster, error) {
for _, dbcluster := range *d {
if *dbcluster.DBClusterIdentifier == *name {
return dbcluster, nil
}
}
return types.DBCluster{}, errors.New("該当のクラスタが存在しません。")
}