Skip to content

Commit

Permalink
feat - sort rds/logs
Browse files Browse the repository at this point in the history
  • Loading branch information
Nicola Strappazzon C committed Oct 15, 2023
1 parent 04bec17 commit 72e8387
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
22 changes: 22 additions & 0 deletions aws/rds/logs.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package rds

import (
"sort"

"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/service/rds"
)
Expand All @@ -24,3 +26,23 @@ func (l *Logs) New(input *rds.DescribeDBLogFilesOutput) *Logs {

return l
}

// Len is part of sort.Interface.
func (l Logs) Len() int {
return len(l)
}

// Less is part of sort.Interface.
// We use count as the value to sort by
func (l Logs) Less(i, j int) bool {
return l[i].Size < l[j].Size
}

// Swap is part of sort.Interface.
func (l Logs) Swap(i, j int) {
l[i], l[j] = l[j], l[i]
}

func (l Logs) SortBySize() {
sort.Sort(l)
}
3 changes: 2 additions & 1 deletion aws/rds/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,11 @@ func (c *Config) Describe(identifier string) (Instance, error) {
return *instance.New(result.DBInstances[0]), nil
}

func (c *Config) Logs(identifier string) (Logs, error) {
func (c *Config) Logs(identifier, filename string) (Logs, error) {
logs := Logs{}
input := &rds.DescribeDBLogFilesInput{
DBInstanceIdentifier: aws.String(identifier),
FilenameContains: aws.String(filename),
}

result, err := c.Client.DescribeDBLogFiles(input)
Expand Down

0 comments on commit 72e8387

Please sign in to comment.