Skip to content

Commit 9d9cfee

Browse files
author
Nicola Strappazzon C
committed
some changes
1 parent 85e7611 commit 9d9cfee

File tree

6 files changed

+43
-7
lines changed

6 files changed

+43
-7
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# go-common
22

3-
Golang library for common projects on DeBeAndo.
3+
Golang library for common projects on DeBeAndo. When the module is mature or complex, is exported to other repository.
44

55
## Usage
66

aws/rds/logs.go

+10-2
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,13 @@ type Log struct {
1515
Size int64 // In bytes, file with 75396 bytes is empty.
1616
}
1717

18-
func (l *Logs) New(input *rds.DescribeDBLogFilesOutput) *Logs {
18+
func NewLogs() Logs {
19+
return Logs{}
20+
}
21+
22+
func (l *Logs) Decode(input *rds.DescribeDBLogFilesOutput) *Logs {
1923
for _, log := range input.DescribeDBLogFiles {
20-
*l = append(*l, Log{
24+
l.Add(Log{
2125
LastWritten: aws.Int64Value(log.LastWritten),
2226
FileName: aws.StringValue(log.LogFileName),
2327
Size: aws.Int64Value(log.Size),
@@ -27,6 +31,10 @@ func (l *Logs) New(input *rds.DescribeDBLogFilesOutput) *Logs {
2731
return l
2832
}
2933

34+
func (l *Logs) Add(in Log) {
35+
*l = append(*l, in)
36+
}
37+
3038
// Len is part of sort.Interface.
3139
func (l Logs) Len() int {
3240
return len(l)

aws/rds/logs_test.go

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package rds_test
2+
3+
import (
4+
"testing"
5+
6+
"github.com/debeando/go-common/aws/rds"
7+
8+
"github.com/stretchr/testify/assert"
9+
)
10+
11+
func TestLogsSort(t *testing.T) {
12+
logs := rds.NewLogs()
13+
logs.Add(rds.Log{Size: int64(6988063)})
14+
logs.Add(rds.Log{Size: int64(27260625)})
15+
logs.Add(rds.Log{Size: int64(1398553)})
16+
logs.Add(rds.Log{Size: int64(18925915)})
17+
18+
t.Log(logs.Len())
19+
20+
// logs.SortBySize()
21+
22+
for _, log := range logs {
23+
t.Log(log.Size)
24+
}
25+
26+
assert.True(t, true)
27+
}

aws/rds/main.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ func (r *RDS) Logs(identifier, filename string) (Logs, error) {
7373
return Logs{}, err
7474
}
7575

76-
return *logs.New(result), nil
76+
return *logs.Decode(result), nil
7777
}
7878

7979
func (r *RDS) PollLogs(identifier, filename string) (string, error) {
@@ -147,7 +147,7 @@ func (r *RDS) CreateReplica(instance Instance) error {
147147
DeletionProtection: aws.Bool(false),
148148
EnableCustomerOwnedIp: aws.Bool(false),
149149
EnableIAMDatabaseAuthentication: aws.Bool(false),
150-
EnablePerformanceInsights: aws.Bool(false),
150+
EnablePerformanceInsights: aws.Bool(true),
151151
MultiAZ: aws.Bool(false),
152152
PubliclyAccessible: aws.Bool(false),
153153
SourceDBInstanceIdentifier: aws.String(instance.Identifier),

mysql/main.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,8 @@ func New(name, dsn string) *Connection {
2424
Name: name,
2525
DSN: dsn,
2626
}
27-
instance[name].Name = name
2827
}
29-
return instance[name]
28+
return Get(name)
3029
}
3130

3231
func Get(name string) *Connection {

table/rows.go

+2
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ func (r *Rows) SortBy(i int) {
2222
switch t.Name() {
2323
case "int":
2424
return int(v1.Int()) < int(v2.Int())
25+
case "int64":
26+
return int64(v1.Int()) < int64(v2.Int())
2527
case "float64":
2628
return v1.Float() < v2.Float()
2729
case "string":

0 commit comments

Comments
 (0)