Skip to content

Commit 10223e0

Browse files
authored
Merge pull request #102 from fujiwara/fix/go-modernize
go fix (modernize)
2 parents 072b703 + c55e44a commit 10223e0

File tree

5 files changed

+31
-39
lines changed

5 files changed

+31
-39
lines changed

filter.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,6 @@ func runInternalFilter(ctx context.Context, src io.Reader, title string) (string
6060
}
6161
var found []string
6262
for _, item := range items {
63-
item := item
6463
if item == input {
6564
found = []string{item}
6665
break

format.go

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -175,12 +175,12 @@ func (t *taskFormatterJSON) AddTask(task types.Task) {
175175
func (t *taskFormatterJSON) Close() {
176176
}
177177

178-
func MarshalJSONForAPI(v interface{}, query *gojq.Query) ([]byte, error) {
178+
func MarshalJSONForAPI(v any, query *gojq.Query) ([]byte, error) {
179179
b, err := json.Marshal(v)
180180
if err != nil {
181181
return nil, err
182182
}
183-
m := map[string]interface{}{}
183+
m := map[string]any{}
184184
if err := json.Unmarshal(b, &m); err != nil {
185185
return nil, err
186186
}
@@ -206,8 +206,8 @@ func MarshalJSONForAPI(v interface{}, query *gojq.Query) ([]byte, error) {
206206
}
207207
}
208208

209-
func UnmarshalJSONForStruct(src []byte, v interface{}) error {
210-
m := map[string]interface{}{}
209+
func UnmarshalJSONForStruct(src []byte, v any) error {
210+
m := map[string]any{}
211211
if err := json.Unmarshal(src, &m); err != nil {
212212
return err
213213
}
@@ -233,26 +233,26 @@ func jsonKeyForStruct(s string) string {
233233
return strings.ToUpper(s[:1]) + s[1:]
234234
}
235235

236-
func walkMap(m map[string]interface{}, fn func(string) string) {
236+
func walkMap(m map[string]any, fn func(string) string) {
237237
for key, value := range m {
238238
delete(m, key)
239239
m[fn(key)] = value
240240
switch value := value.(type) {
241-
case map[string]interface{}:
241+
case map[string]any:
242242
walkMap(value, fn)
243-
case []interface{}:
243+
case []any:
244244
walkArray(value, fn)
245245
default:
246246
}
247247
}
248248
}
249249

250-
func walkArray(a []interface{}, fn func(string) string) {
250+
func walkArray(a []any, fn func(string) string) {
251251
for _, value := range a {
252252
switch value := value.(type) {
253-
case map[string]interface{}:
253+
case map[string]any:
254254
walkMap(value, fn)
255-
case []interface{}:
255+
case []any:
256256
walkArray(value, fn)
257257
default:
258258
}

portforward.go

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,15 @@ import (
1717
)
1818

1919
type PortforwardOption struct {
20-
ID string `help:"task ID"`
21-
Container string `help:"container name"`
22-
LocalPort int `help:"local port"`
23-
RemotePort int `help:"remote port"`
24-
RemoteHost string `help:"remote host"`
25-
L string `name:"L" help:"short expression of local-port:remote-host:remote-port" short:"L"`
26-
Family *string `help:"task definition family name"`
27-
Service *string `help:"ECS service name"`
28-
Public bool `help:"bind to all interfaces (0.0.0.0) instead of localhost only"`
20+
ID string `help:"task ID"`
21+
Container string `help:"container name"`
22+
LocalPort int `help:"local port"`
23+
RemotePort int `help:"remote port"`
24+
RemoteHost string `help:"remote host"`
25+
L string `name:"L" help:"short expression of local-port:remote-host:remote-port" short:"L"`
26+
Family *string `help:"task definition family name"`
27+
Service *string `help:"ECS service name"`
28+
Public bool `help:"bind to all interfaces (0.0.0.0) instead of localhost only"`
2929

3030
stdout io.Writer
3131
stderr io.Writer
@@ -129,14 +129,14 @@ func (app *Ecsta) RunPortforward(ctx context.Context, opt *PortforwardOption) er
129129
if opt.Public {
130130
slog.Warn("TCP proxy will bind to all interfaces (0.0.0.0) - ensure proper network security", "port", opt.LocalPort)
131131
slog.Info("Session Manager Plugin will use port", "port", ssmLocalPort)
132-
132+
133133
// Start TCP proxy in background
134134
go func() {
135135
if err := app.startTCPProxyToLocalhost(ctx, "0.0.0.0", opt.LocalPort, ssmLocalPort); err != nil {
136136
slog.Error("TCP proxy failed", "error", err)
137137
}
138138
}()
139-
139+
140140
// Wait a bit for proxy to start
141141
time.Sleep(200 * time.Millisecond)
142142
}
@@ -194,7 +194,7 @@ func (app *Ecsta) handleProxyConnection(ctx context.Context, clientConn net.Conn
194194
// Start bidirectional copy with context cancellation
195195
var wg sync.WaitGroup
196196
done := make(chan struct{})
197-
197+
198198
wg.Add(2)
199199

200200
// Copy from client to backend
@@ -232,4 +232,3 @@ func (app *Ecsta) handleProxyConnection(ctx context.Context, clientConn net.Conn
232232
wg.Wait()
233233
}
234234
}
235-

portforward_integration_test.go

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,7 @@ func TestTCPProxyToLocalhost(t *testing.T) {
2626
backendCtx, backendCancel := context.WithCancel(context.Background())
2727
defer backendCancel()
2828

29-
backendWg.Add(1)
30-
go func() {
31-
defer backendWg.Done()
29+
backendWg.Go(func() {
3230
for {
3331
select {
3432
case <-backendCtx.Done():
@@ -63,7 +61,7 @@ func TestTCPProxyToLocalhost(t *testing.T) {
6361
}
6462
}(conn)
6563
}
66-
}()
64+
})
6765

6866
// Get a different port for proxy frontend
6967
proxyListener, err := net.Listen("tcp", "0.0.0.0:0")
@@ -79,14 +77,12 @@ func TestTCPProxyToLocalhost(t *testing.T) {
7977
defer cancel()
8078

8179
var proxyWg sync.WaitGroup
82-
proxyWg.Add(1)
83-
go func() {
84-
defer proxyWg.Done()
80+
proxyWg.Go(func() {
8581
err := app.startTCPProxyToLocalhost(ctx, "0.0.0.0", proxyPort, backendPort)
8682
if err != nil && err != context.DeadlineExceeded && err != context.Canceled {
8783
t.Logf("Proxy ended with: %v", err)
8884
}
89-
}()
85+
})
9086

9187
// Wait a bit for proxy to start
9288
time.Sleep(50 * time.Millisecond)
@@ -125,7 +121,7 @@ func TestTCPProxyToLocalhost(t *testing.T) {
125121
// Cleanup: cancel contexts and wait for goroutines
126122
cancel()
127123
backendCancel()
128-
124+
129125
// Wait for goroutines to finish with timeout
130126
done := make(chan struct{})
131127
go func() {
@@ -192,11 +188,9 @@ func TestHandleProxyConnection(t *testing.T) {
192188

193189
// Start handleProxyConnection
194190
var proxyWg sync.WaitGroup
195-
proxyWg.Add(1)
196-
go func() {
197-
defer proxyWg.Done()
191+
proxyWg.Go(func() {
198192
app.handleProxyConnection(proxyCtx, serverConn, backendPort)
199-
}()
193+
})
200194

201195
// Test communication
202196
testData := "test data"
@@ -233,4 +227,4 @@ func TestHandleProxyConnection(t *testing.T) {
233227
case <-time.After(1 * time.Second):
234228
t.Log("Warning: proxy goroutine did not finish within timeout")
235229
}
236-
}
230+
}

portforward_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,4 +109,4 @@ func TestPortforwardOption_PublicFlagValidation(t *testing.T) {
109109
}
110110
})
111111
}
112-
}
112+
}

0 commit comments

Comments
 (0)