Skip to content

Commit a1f808c

Browse files
authored
all: modernize code (#868)
Use `go fix ./...` to modernize the code.
1 parent 74d2751 commit a1f808c

12 files changed

Lines changed: 44 additions & 69 deletions

File tree

auth/extauth/enterprise_handler_test.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ func TestNewEnterpriseHandler_Validation(t *testing.T) {
3636
AccessToken: "mock_access_token",
3737
TokenType: "Bearer",
3838
}
39-
return token.WithExtra(map[string]interface{}{"id_token": "mock_id_token"}), nil
39+
return token.WithExtra(map[string]any{"id_token": "mock_id_token"}), nil
4040
},
4141
}
4242

@@ -194,7 +194,7 @@ func TestNewEnterpriseHandler_Validation(t *testing.T) {
194194
AccessToken: "mock_access_token",
195195
TokenType: "Bearer",
196196
}
197-
return token.WithExtra(map[string]interface{}{"id_token": "mock_id_token"}), nil
197+
return token.WithExtra(map[string]any{"id_token": "mock_id_token"}), nil
198198
},
199199
},
200200
wantError: "",
@@ -254,7 +254,7 @@ func TestEnterpriseHandler_Authorize_E2E(t *testing.T) {
254254
AccessToken: "mock_access_token",
255255
TokenType: "Bearer",
256256
}
257-
return token.WithExtra(map[string]interface{}{"id_token": "mock_id_token_from_user_login"}), nil
257+
return token.WithExtra(map[string]any{"id_token": "mock_id_token_from_user_login"}), nil
258258
},
259259
})
260260
if err != nil {
@@ -305,7 +305,7 @@ func setupIdPServer(t *testing.T) *httptest.Server {
305305
// OAuth/OIDC metadata endpoint - uses closure to get server URL
306306
mux.HandleFunc("/.well-known/oauth-authorization-server", func(w http.ResponseWriter, r *http.Request) {
307307
w.Header().Set("Content-Type", "application/json")
308-
json.NewEncoder(w).Encode(map[string]interface{}{
308+
json.NewEncoder(w).Encode(map[string]any{
309309
"issuer": server.URL,
310310
"token_endpoint": server.URL + "/token",
311311
"authorization_endpoint": server.URL + "/authorize",
@@ -350,7 +350,7 @@ func setupIdPServer(t *testing.T) *httptest.Server {
350350

351351
// Return ID-JAG (Identity Assertion JWT Authorization Grant)
352352
w.Header().Set("Content-Type", "application/json")
353-
json.NewEncoder(w).Encode(map[string]interface{}{
353+
json.NewEncoder(w).Encode(map[string]any{
354354
"access_token": "id-jag-token-from-idp",
355355
"issued_token_type": oauthex.TokenTypeIDJAG,
356356
"token_type": "N_A",
@@ -375,7 +375,7 @@ func setupMCPAuthServer(t *testing.T) *httptest.Server {
375375
// OAuth metadata endpoint - uses closure to get server URL
376376
mux.HandleFunc("/.well-known/oauth-authorization-server", func(w http.ResponseWriter, r *http.Request) {
377377
w.Header().Set("Content-Type", "application/json")
378-
json.NewEncoder(w).Encode(map[string]interface{}{
378+
json.NewEncoder(w).Encode(map[string]any{
379379
"issuer": server.URL,
380380
"token_endpoint": server.URL + "/token",
381381
"code_challenge_methods_supported": []string{"S256"},
@@ -412,7 +412,7 @@ func setupMCPAuthServer(t *testing.T) *httptest.Server {
412412

413413
// Return access token
414414
w.Header().Set("Content-Type", "application/json")
415-
json.NewEncoder(w).Encode(map[string]interface{}{
415+
json.NewEncoder(w).Encode(map[string]any{
416416
"access_token": "mcp_access_token_from_jwt_bearer",
417417
"token_type": "Bearer",
418418
"expires_in": 3600,
@@ -480,7 +480,7 @@ func TestEnterpriseHandler_TokenSource_BeforeAuthorization(t *testing.T) {
480480
AccessToken: "mock_access_token",
481481
TokenType: "Bearer",
482482
}
483-
return token.WithExtra(map[string]interface{}{"id_token": "mock_id_token"}), nil
483+
return token.WithExtra(map[string]any{"id_token": "mock_id_token"}), nil
484484
},
485485
})
486486
if err != nil {

auth/extauth/oidc_login_test.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -327,7 +327,7 @@ func createMockOIDCServer(t *testing.T) *httptest.Server {
327327
// Handle OIDC discovery
328328
if r.URL.Path == "/.well-known/openid-configuration" {
329329
w.Header().Set("Content-Type", "application/json")
330-
json.NewEncoder(w).Encode(map[string]interface{}{
330+
json.NewEncoder(w).Encode(map[string]any{
331331
"issuer": serverURL,
332332
"authorization_endpoint": serverURL + "/authorize",
333333
"token_endpoint": serverURL + "/token",
@@ -351,7 +351,7 @@ func createMockOIDCServerWithToken(t *testing.T) *httptest.Server {
351351
// Handle OIDC discovery
352352
if r.URL.Path == "/.well-known/openid-configuration" {
353353
w.Header().Set("Content-Type", "application/json")
354-
json.NewEncoder(w).Encode(map[string]interface{}{
354+
json.NewEncoder(w).Encode(map[string]any{
355355
"issuer": serverURL,
356356
"authorization_endpoint": serverURL + "/authorize",
357357
"token_endpoint": serverURL + "/token",
@@ -376,7 +376,7 @@ func createMockOIDCServerWithToken(t *testing.T) *httptest.Server {
376376
// Create mock ID token (JWT)
377377
now := time.Now().Unix()
378378
idToken := fmt.Sprintf("eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9.%s.mock-signature",
379-
base64EncodeClaims(map[string]interface{}{
379+
base64EncodeClaims(map[string]any{
380380
"iss": serverURL,
381381
"sub": "test-user",
382382
"aud": "test-client",
@@ -386,7 +386,7 @@ func createMockOIDCServerWithToken(t *testing.T) *httptest.Server {
386386
}))
387387
// Return token response
388388
w.Header().Set("Content-Type", "application/json")
389-
json.NewEncoder(w).Encode(map[string]interface{}{
389+
json.NewEncoder(w).Encode(map[string]any{
390390
"access_token": "mock-access-token",
391391
"token_type": "Bearer",
392392
"expires_in": 3600,
@@ -402,7 +402,7 @@ func createMockOIDCServerWithToken(t *testing.T) *httptest.Server {
402402
}
403403

404404
// base64EncodeClaims encodes JWT claims for testing.
405-
func base64EncodeClaims(claims map[string]interface{}) string {
405+
func base64EncodeClaims(claims map[string]any) string {
406406
claimsJSON, _ := json.Marshal(claims)
407407
return base64.RawURLEncoding.EncodeToString(claimsJSON)
408408
}

examples/client/loadtest/main.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -69,9 +69,7 @@ func main() {
6969
// Run the test.
7070
var wg sync.WaitGroup
7171
for range *workers {
72-
wg.Add(1)
73-
go func() {
74-
defer wg.Done()
72+
wg.Go(func() {
7573
client := mcp.NewClient(&mcp.Implementation{Name: "mcp-client", Version: "v1.0.0"}, nil)
7674
cs, err := client.Connect(parentCtx, &mcp.StreamableClientTransport{Endpoint: args[0]}, nil)
7775
if err != nil {
@@ -108,7 +106,7 @@ func main() {
108106
}
109107
}
110108
}
111-
}()
109+
})
112110
}
113111
wg.Wait()
114112
stop() // restore the interrupt signal

examples/server/distributed/main.go

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -89,16 +89,14 @@ func parent() {
8989
cmd.Env = append(os.Environ(), fmt.Sprintf("%s=%s", childPortVar, port))
9090
cmd.Stderr = os.Stderr
9191

92-
wg.Add(1)
93-
go func() {
94-
defer wg.Done()
92+
wg.Go(func() {
9593
log.Printf("starting child %d at %s", i, childURL)
9694
if err := cmd.Run(); err != nil && ctx.Err() == nil {
9795
log.Printf("child %d failed: %v", i, err)
9896
} else {
9997
log.Printf("child %d exited gracefully", i)
10098
}
101-
}()
99+
})
102100
}
103101

104102
// Start a reverse proxy that round-robin's requests to each backend.
@@ -116,13 +114,11 @@ func parent() {
116114
},
117115
}
118116

119-
wg.Add(1)
120-
go func() {
121-
defer wg.Done()
117+
wg.Go(func() {
122118
if err := server.ListenAndServe(); err != nil && ctx.Err() == nil {
123119
log.Printf("Server failed: %v", err)
124120
}
125-
}()
121+
})
126122

127123
log.Printf("Serving at %s (CTRL-C to cancel)", *httpAddr)
128124

internal/oauthtest/fake_authorization_server.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,7 @@ func (s *FakeAuthorizationServer) handleToken(w http.ResponseWriter, r *http.Req
282282
}
283283

284284
w.Header().Set("Content-Type", "application/json")
285-
json.NewEncoder(w).Encode(map[string]interface{}{
285+
json.NewEncoder(w).Encode(map[string]any{
286286
"access_token": "test_access_token",
287287
"token_type": "Bearer",
288288
"expires_in": 3600,

mcp/cmd_test.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -200,8 +200,7 @@ func TestStdioContextCancellation(t *testing.T) {
200200
func TestCmdTransport(t *testing.T) {
201201
requireExec(t)
202202

203-
ctx, cancel := context.WithCancel(context.Background())
204-
defer cancel()
203+
ctx := t.Context()
205204

206205
cmd := createServerCommand(t, "default")
207206

@@ -287,8 +286,7 @@ func TestCommandTransportTerminateDuration(t *testing.T) {
287286

288287
for _, tt := range tests {
289288
t.Run(tt.name, func(t *testing.T) {
290-
ctx, cancel := context.WithCancel(context.Background())
291-
defer cancel()
289+
ctx := t.Context()
292290

293291
// Use a command that won't exit when stdin is closed
294292
cmd := exec.Command("sleep", "20")

mcp/content_nil_test.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ func TestContentUnmarshalNil(t *testing.T) {
2222
tests := []struct {
2323
name string
2424
json string
25-
content interface{}
26-
want interface{}
25+
content any
26+
want any
2727
}{
2828
{
2929
name: "CallToolResult nil Content",
@@ -83,7 +83,7 @@ func TestContentUnmarshalNilWithDifferentTypes(t *testing.T) {
8383
tests := []struct {
8484
name string
8585
json string
86-
content interface{}
86+
content any
8787
expectError bool
8888
}{
8989
{
@@ -145,7 +145,7 @@ func TestContentUnmarshalNilWithEmptyContent(t *testing.T) {
145145
tests := []struct {
146146
name string
147147
json string
148-
content interface{}
148+
content any
149149
expectError bool
150150
}{
151151
{
@@ -186,7 +186,7 @@ func TestContentUnmarshalNilWithInvalidContent(t *testing.T) {
186186
tests := []struct {
187187
name string
188188
json string
189-
content interface{}
189+
content any
190190
expectError bool
191191
}{
192192
{

mcp/mcp_test.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -676,13 +676,11 @@ func TestServerClosing(t *testing.T) {
676676

677677
ctx := context.Background()
678678
var wg sync.WaitGroup
679-
wg.Add(1)
680-
go func() {
679+
wg.Go(func() {
681680
if err := cs.Wait(); err != nil {
682681
t.Errorf("server connection failed: %v", err)
683682
}
684-
wg.Done()
685-
}()
683+
})
686684
if _, err := cs.CallTool(ctx, &CallToolParams{
687685
Name: "greet",
688686
Arguments: map[string]any{"Name": "user"},

mcp/schema_cache_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ func TestAddToolWithSharedCache(t *testing.T) {
194194
}
195195

196196
// Simulate stateless server pattern: new server per request, shared cache.
197-
for i := 0; i < 3; i++ {
197+
for range 3 {
198198
s := NewServer(&Implementation{Name: "test", Version: "1.0"}, &ServerOptions{
199199
SchemaCache: cache,
200200
})

mcp/streamable_bench_test.go

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
package mcp_test
66

77
import (
8-
"context"
98
"flag"
109
"log"
1110
"net/http"
@@ -51,8 +50,7 @@ func BenchmarkStreamableServing(b *testing.B) {
5150
httpServer := httptest.NewServer(handler)
5251
defer httpServer.Close()
5352

54-
ctx, cancel := context.WithCancel(context.Background())
55-
defer cancel()
53+
ctx := b.Context()
5654
session, err := mcp.NewClient(testImpl, nil).Connect(ctx, &mcp.StreamableClientTransport{Endpoint: httpServer.URL}, nil)
5755
if err != nil {
5856
b.Fatal(err)
@@ -84,8 +82,7 @@ func BenchmarkStreamableServing_BadSessions(b *testing.B) {
8482
httpServer := httptest.NewServer(handler)
8583
defer httpServer.Close()
8684

87-
ctx, cancel := context.WithCancel(context.Background())
88-
defer cancel()
85+
ctx := b.Context()
8986

9087
if *streamableHeap != "" {
9188
writeHeap := func(file string) {

0 commit comments

Comments
 (0)