Skip to content

Commit 0654797

Browse files
committed
go fmt
1 parent 260f756 commit 0654797

9 files changed

+265
-262
lines changed

history.go

+23-23
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,14 @@ package main
33
import (
44
"errors"
55
"path/filepath"
6-
"time"
6+
"time"
77
)
88

99
type HistoryItem struct {
10-
Source string
11-
Dest string
10+
Source string
11+
Dest string
1212
Timestamp int64
13-
Id string
13+
Id string
1414
}
1515

1616
func normalizePath(p string) string {
@@ -28,58 +28,58 @@ func clearHistory() error {
2828

2929
func allHistoryItems() ([]HistoryItem, error) {
3030
var output []HistoryItem
31-
31+
3232
rows, err := profileDb_.Query("SELECT id, source, destination, timestamp FROM history ORDER BY id")
3333
if err != nil {
3434
return output, err
3535
}
36-
36+
3737
for rows.Next() {
3838
var item HistoryItem
3939
rows.Scan(&item.Id, &item.Source, &item.Dest, &item.Timestamp)
4040
output = append(output, item)
4141
}
42-
42+
4343
return output, nil
4444
}
4545

4646
func saveHistoryItems(sources []string, destinations []string) error {
4747
if len(sources) != len(destinations) {
4848
return errors.New("Number of sources and destinations do not match.")
4949
}
50-
50+
5151
if len(sources) == 0 {
5252
return nil
5353
}
54-
54+
5555
tx, err := profileDb_.Begin()
5656
if err != nil {
5757
return err
5858
}
59-
59+
6060
for i, source := range sources {
6161
dest := destinations[i]
62-
tx.Exec("INSERT INTO history (source, destination, timestamp) VALUES (?, ?, ?)", normalizePath(source), normalizePath(dest), time.Now().Unix())
62+
tx.Exec("INSERT INTO history (source, destination, timestamp) VALUES (?, ?, ?)", normalizePath(source), normalizePath(dest), time.Now().Unix())
6363
}
64-
64+
6565
return tx.Commit()
6666
}
6767

6868
func deleteHistoryItems(items []HistoryItem) error {
6969
if len(items) == 0 {
7070
return nil
7171
}
72-
72+
7373
sqlOr := ""
7474
for _, item := range items {
7575
if sqlOr != "" {
7676
sqlOr += " OR "
7777
}
7878
sqlOr += "id = " + item.Id
7979
}
80-
80+
8181
_, err := profileDb_.Exec("DELETE FROM history WHERE " + sqlOr)
82-
82+
8383
return err
8484
}
8585

@@ -89,13 +89,13 @@ func deleteOldHistoryItems(minTimestamp int64) {
8989
}
9090
}
9191

92-
func latestHistoryItemsByDestinations(paths []string) ([]HistoryItem, error) {
92+
func latestHistoryItemsByDestinations(paths []string) ([]HistoryItem, error) {
9393
var output []HistoryItem
9494
if len(paths) == 0 {
9595
return output, nil
9696
}
97-
98-
sqlOr := ""
97+
98+
sqlOr := ""
9999
var sqlArgs []interface{}
100100
for _, p := range paths {
101101
sqlArgs = append(sqlArgs, p)
@@ -104,12 +104,12 @@ func latestHistoryItemsByDestinations(paths []string) ([]HistoryItem, error) {
104104
}
105105
sqlOr += "destination = ?"
106106
}
107-
108-
rows, err := profileDb_.Query("SELECT id, source, destination, timestamp FROM history WHERE " + sqlOr + " ORDER BY timestamp DESC", sqlArgs...)
107+
108+
rows, err := profileDb_.Query("SELECT id, source, destination, timestamp FROM history WHERE "+sqlOr+" ORDER BY timestamp DESC", sqlArgs...)
109109
if err != nil {
110110
return output, err
111111
}
112-
112+
113113
doneDestinations := make(map[string]bool)
114114
for rows.Next() {
115115
var item HistoryItem
@@ -121,6 +121,6 @@ func latestHistoryItemsByDestinations(paths []string) ([]HistoryItem, error) {
121121
output = append(output, item)
122122
doneDestinations[item.Dest] = true
123123
}
124-
124+
125125
return output, nil
126-
}
126+
}

history_test.go

+20-20
Original file line numberDiff line numberDiff line change
@@ -8,43 +8,43 @@ import (
88
func Test_saveHistoryItems(t *testing.T) {
99
setup(t)
1010
defer teardown(t)
11-
11+
1212
err := saveHistoryItems([]string{"one", "two"}, []string{"one"})
1313
if err == nil {
1414
t.Error("Expected error, got nil")
1515
}
16-
16+
1717
err = saveHistoryItems([]string{}, []string{})
1818
if err != nil {
1919
t.Errorf("Expected no error, got %s", err)
2020
}
21-
21+
2222
items, _ := allHistoryItems()
2323
if len(items) > 0 {
2424
t.Errorf("Expected no items, got %d", len(items))
2525
}
26-
27-
saveHistoryItems([]string{"one","two"}, []string{"1","2"})
28-
26+
27+
saveHistoryItems([]string{"one", "two"}, []string{"1", "2"})
28+
2929
items, _ = allHistoryItems()
3030
if len(items) != 2 {
3131
t.Errorf("Expected 2 items, got %d", len(items))
3232
}
33-
33+
3434
for _, item := range items {
3535
if (filepath.Base(item.Source) == "one" && filepath.Base(item.Dest) != "1") || (filepath.Base(item.Source) == "two" && filepath.Base(item.Dest) != "2") {
3636
t.Error("Source and destination do not match.")
3737
}
3838
}
39-
39+
4040
saveHistoryItems([]string{"three"}, []string{"3"})
4141
items, _ = allHistoryItems()
4242
if len(items) != 3 {
4343
t.Errorf("Expected 3 items, got %d", len(items))
4444
}
45-
45+
4646
profileDb_.Close()
47-
47+
4848
err = saveHistoryItems([]string{"un"}, []string{"dest"})
4949
if err == nil {
5050
t.Error("Expected error, got nil")
@@ -55,11 +55,11 @@ func Test_deleteHistoryItems(t *testing.T) {
5555
setup(t)
5656
defer teardown(t)
5757

58-
saveHistoryItems([]string{"one","two","three"}, []string{"1","2","3"})
59-
58+
saveHistoryItems([]string{"one", "two", "three"}, []string{"1", "2", "3"})
59+
6060
items, _ := allHistoryItems()
6161
deleteHistoryItems([]HistoryItem{items[0], items[1]})
62-
62+
6363
items, _ = allHistoryItems()
6464
if len(items) != 1 {
6565
t.Errorf("Expected 1 item, got %d", len(items))
@@ -76,10 +76,10 @@ func Test_deleteOldHistoryItems(t *testing.T) {
7676

7777
now := 1000
7878
for i := 0; i < 5; i++ {
79-
profileDb_.Exec("INSERT INTO history (source, destination, timestamp) VALUES (?, ?, ?)", "a", "b", now + i)
79+
profileDb_.Exec("INSERT INTO history (source, destination, timestamp) VALUES (?, ?, ?)", "a", "b", now+i)
8080
}
8181
deleteOldHistoryItems(int64(now + 2))
82-
82+
8383
items, _ := allHistoryItems()
8484
if len(items) != 3 {
8585
t.Errorf("Expected 3 items, got %d", len(items))
@@ -92,18 +92,18 @@ func Test_latestHistoryItemsByDestinations(t *testing.T) {
9292

9393
now := 1000
9494
for i := 0; i < 5; i++ {
95-
profileDb_.Exec("INSERT INTO history (source, destination, timestamp) VALUES (?, ?, ?)", "a", "b", now + i)
95+
profileDb_.Exec("INSERT INTO history (source, destination, timestamp) VALUES (?, ?, ?)", "a", "b", now+i)
9696
}
97-
97+
9898
items, _ := allHistoryItems()
9999
dest := items[0].Dest
100-
100+
101101
items, _ = latestHistoryItemsByDestinations([]string{dest})
102102
if len(items) != 1 {
103103
t.Errorf("Expected 1 item, got %d", len(items))
104104
} else {
105105
if items[0].Timestamp != 1004 {
106-
t.Error("Did not get the right item")
106+
t.Error("Did not get the right item")
107107
}
108108
}
109-
}
109+
}

log.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ func log(level int, s string, a ...interface{}) {
1010
if level < minLogLevel_ {
1111
return
1212
}
13-
fmt.Printf(APPNAME + ": " + s + "\n", a...)
13+
fmt.Printf(APPNAME+": "+s+"\n", a...)
1414
}
1515

1616
func logDebug(s string, a ...interface{}) {
@@ -23,4 +23,4 @@ func logInfo(s string, a ...interface{}) {
2323

2424
func logError(s string, a ...interface{}) {
2525
log(3, s, a...)
26-
}
26+
}

0 commit comments

Comments
 (0)