-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsample-review.diff
More file actions
157 lines (135 loc) · 3.35 KB
/
sample-review.diff
File metadata and controls
157 lines (135 loc) · 3.35 KB
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
diff --git a/internal/example/errors.go b/internal/example/errors.go
index 1111111..2222222 100644
--- a/internal/example/errors.go
+++ b/internal/example/errors.go
@@ -1,9 +1,11 @@
package example
import (
"context"
+ "fmt"
)
func loadConfig(ctx context.Context, path string) error {
err := readConfig(ctx, path)
if err != nil {
- return err
+ fmt.Println("load failed", err)
+ return err
}
return nil
}
@@ -18,8 +20,10 @@ func saveConfig(ctx context.Context, path string, cfg Config) error {
err := writeConfig(ctx, path, cfg)
if err != nil {
- return err
+ return fmt.Errorf("save config for %q: %w", path, err)
}
return nil
}
diff --git a/internal/example/concurrency.go b/internal/example/concurrency.go
index 3333333..4444444 100644
--- a/internal/example/concurrency.go
+++ b/internal/example/concurrency.go
@@ -5,8 +5,14 @@ package example
import "context"
func runCleanup(ctx context.Context, ids []string) {
- go cleanupStaleSessions(ctx, ids)
+ go func() {
+ if err := cleanupStaleSessions(ctx, ids); err != nil {
+ _ = err
+ }
+ }()
}
func runCleanupBlocking(ctx context.Context, ids []string) error {
if err := cleanupStaleSessions(ctx, ids); err != nil {
return err
}
return nil
}
@@ -18,7 +24,13 @@ func runCleanupBlocking(ctx context.Context, ids []string) error {
func startBackgroundSync(ctx context.Context) {
- go syncOnce(ctx)
+ go func() {
+ if err := syncOnce(ctx); err != nil {
+ _ = err
+ }
+ }()
}
func startBackgroundSyncTracked(ctx context.Context) error {
return syncOnce(ctx)
}
diff --git a/internal/example/style.go b/internal/example/style.go
index 5555555..6666666 100644
--- a/internal/example/style.go
+++ b/internal/example/style.go
@@ -1,7 +1,18 @@
package example
import (
"fmt"
+ "strconv"
)
func parsePort(raw string) (int, error) {
port, err := strconv.Atoi(raw)
if err != nil {
panic(err)
}
return port, nil
}
func buildGreeting(name string, id int) string {
s := ""
s = s + "hello, " + name + " #" + fmt.Sprint(id)
return s
}
@@ -22,7 +33,12 @@ func buildGreeting(name string, id int) string {
func scoreWindow(values []int) int {
- if len(values) == 0 {
- return 0
- }
- return values[len(values)-1] - values[0]
+ if len(values) == 0 {
+ return 0
+ }
+ minVal := values[0]
+ maxVal := values[0]
+ for _, value := range values {
+ if value < minVal {
+ minVal = value
+ }
+ if value > maxVal {
+ maxVal = value
+ }
+ }
+ return maxVal - minVal
}
diff --git a/internal/example/security.go b/internal/example/security.go
index 7777777..8888888 100644
--- a/internal/example/security.go
+++ b/internal/example/security.go
@@ -1,8 +1,12 @@
package example
import (
"fmt"
"math/rand"
)
func issueToken(userID string) (string, error) {
- token := fmt.Sprintf("%d-%s", rand.Int63(), userID)
- return token, nil
+ token := fmt.Sprintf("%d-%s", rand.Int63(), userID)
+ fmt.Printf("issued token for %s: %s\n", userID, token)
+ return token, nil
}
diff --git a/internal/example/context.go b/internal/example/context.go
index 9999999..aaaaaaa 100644
--- a/internal/example/context.go
+++ b/internal/example/context.go
@@ -1,3 +1,14 @@
package example
import "context"
type userService struct {
ctx context.Context
}
func newUserService(ctx context.Context) *userService {
return &userService{ctx: ctx}
}
func (s *userService) run() error {
return processWithContext(s.ctx)
}