Skip to content

Commit c91da02

Browse files
paskalumputun
authored andcommitted
chore: go fix ./...
Apply Go modernization fixes from `go fix ./...` across both v1 and v2: * `interface{}` -> `any` (Go 1.18+ alias) * Other small idiomatic updates No behaviour changes; this is a hygiene pass to make the build green under stricter linters and bring the codebase up to modern Go style. Run with Go 1.25+ as required by CLAUDE.md and go.mod.
1 parent 30e0070 commit c91da02

36 files changed

Lines changed: 84 additions & 86 deletions

avatar/avatar.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@ func GetGravatarURL(email string) (res string, err error) {
243243
}
244244

245245
func retry(retries int, delay time.Duration, fn func() error) (err error) {
246-
for i := 0; i < retries; i++ {
246+
for range retries {
247247
if err = fn(); err == nil {
248248
return nil
249249
}

logger/interface.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,17 @@ import "log"
66

77
// L defined logger interface used everywhere in the package
88
type L interface {
9-
Logf(format string, args ...interface{})
9+
Logf(format string, args ...any)
1010
}
1111

1212
// Func type is an adapter to allow the use of ordinary functions as Logger.
13-
type Func func(format string, args ...interface{})
13+
type Func func(format string, args ...any)
1414

1515
// Logf calls f(id)
16-
func (f Func) Logf(format string, args ...interface{}) { f(format, args...) }
16+
func (f Func) Logf(format string, args ...any) { f(format, args...) }
1717

1818
// NoOp logger
19-
var NoOp = Func(func(string, ...interface{}) {})
19+
var NoOp = Func(func(string, ...any) {})
2020

2121
// Std logger sends to std default logger directly
22-
var Std = Func(func(format string, args ...interface{}) { log.Printf(format, args...) })
22+
var Std = Func(func(format string, args ...any) { log.Printf(format, args...) })

logger/interface_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import (
1313

1414
func TestLogger(t *testing.T) {
1515
buff := bytes.NewBufferString("")
16-
lg := Func(func(format string, args ...interface{}) {
16+
lg := Func(func(format string, args ...any) {
1717
fmt.Fprintf(buff, format, args...)
1818
})
1919

middleware/auth.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ type Authenticator struct {
2828

2929
// RefreshCache defines interface storing and retrieving refreshed tokens
3030
type RefreshCache interface {
31-
Get(key interface{}) (value interface{}, ok bool)
32-
Set(key, value interface{})
31+
Get(key any) (value any, ok bool)
32+
Set(key, value any)
3333
}
3434

3535
// TokenService defines interface accessing tokens
@@ -49,7 +49,7 @@ type BasicAuthFunc func(user, passwd string) (ok bool, userInfo token.User, err
4949
var adminUser = token.User{
5050
ID: "admin",
5151
Name: "admin",
52-
Attributes: map[string]interface{}{
52+
Attributes: map[string]any{
5353
"admin": true,
5454
},
5555
}

middleware/auth_test.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ func TestAuthJWTCookie(t *testing.T) {
4444
assert.NoError(t, err)
4545
assert.Equal(t, token.User{Name: "name1", ID: "provider1_id1", Picture: "http://example.com/pic.png",
4646
IP: "127.0.0.1", Email: "me@example.com", Audience: "test_sys",
47-
Attributes: map[string]interface{}{"boola": true, "stra": "stra-val"}}, u)
47+
Attributes: map[string]any{"boola": true, "stra": "stra-val"}}, u)
4848
w.WriteHeader(201)
4949
}
5050
mux.Handle("/auth", a.Auth(http.HandlerFunc(handler)))
@@ -179,7 +179,7 @@ func TestAuthJWTRefreshConcurrentWithCache(t *testing.T) {
179179
var wg sync.WaitGroup
180180
a.RefreshCache = newTestRefreshCache()
181181
wg.Add(100)
182-
for i := 0; i < 100; i++ {
182+
for range 100 {
183183
time.Sleep(1 * time.Millisecond) // TODO! not sure how testRefreshCache may have misses without this delay
184184
go func() {
185185
defer wg.Done()
@@ -467,7 +467,7 @@ func TestRBAC(t *testing.T) {
467467
assert.NoError(t, err)
468468
assert.Equal(t, token.User{Name: "name1", ID: "provider1_id1", Picture: "http://example.com/pic.png",
469469
IP: "127.0.0.1", Email: "me@example.com", Audience: "test_sys",
470-
Attributes: map[string]interface{}{"boola": true, "stra": "stra-val"},
470+
Attributes: map[string]any{"boola": true, "stra": "stra-val"},
471471
Role: "employee"}, u)
472472
w.WriteHeader(201)
473473
})
@@ -558,16 +558,16 @@ func makeTestAuth(_ *testing.T) Authenticator {
558558
}
559559

560560
type testRefreshCache struct {
561-
data map[interface{}]interface{}
561+
data map[any]any
562562
sync.RWMutex
563563
hits, misses int32
564564
}
565565

566566
func newTestRefreshCache() *testRefreshCache {
567-
return &testRefreshCache{data: make(map[interface{}]interface{})}
567+
return &testRefreshCache{data: make(map[any]any)}
568568
}
569569

570-
func (c *testRefreshCache) Get(key interface{}) (value interface{}, ok bool) {
570+
func (c *testRefreshCache) Get(key any) (value any, ok bool) {
571571
c.RLock()
572572
defer c.RUnlock()
573573
value, ok = c.data[key]
@@ -579,7 +579,7 @@ func (c *testRefreshCache) Get(key interface{}) (value interface{}, ok bool) {
579579
return value, ok
580580
}
581581

582-
func (c *testRefreshCache) Set(key, value interface{}) {
582+
func (c *testRefreshCache) Set(key, value any) {
583583
c.Lock()
584584
defer c.Unlock()
585585
c.data[key] = value

provider/apple.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ type AppleConfig struct {
7676
ResponseMode string // changes method of receiving data in callback. Default value "form_post" (https://developer.apple.com/documentation/sign_in_with_apple/request_an_authorization_to_the_sign_in_with_apple_server?changes=_1_2#4066168)
7777

7878
scopes []string // for this package allow only username scope and UID in token claims. Apple service API provide only "email" and "name" scope values (https://developer.apple.com/documentation/sign_in_with_apple/clientconfigi/3230955-scope)
79-
privateKey interface{} // private key from Apple obtained in developer account (the keys section). Required for create the Client Secret (https://developer.apple.com/documentation/sign_in_with_apple/generate_and_validate_tokens#3262048)
79+
privateKey any // private key from Apple obtained in developer account (the keys section). Required for create the Client Secret (https://developer.apple.com/documentation/sign_in_with_apple/generate_and_validate_tokens#3262048)
8080
publicKey crypto.PublicKey // need for validate sign of token
8181
clientSecret string // is the JWT client secret will create after first call and then used until expired
8282
jwkURL string // URL for fetch JWK Apple keys, need redefine for tests
@@ -228,7 +228,7 @@ func (ah *AppleHandler) initPrivateKey() error {
228228
}
229229

230230
// tokenKeyFunc use for verify JWT sign, it receives the parsed token and should return the key for validating.
231-
func (ah *AppleHandler) tokenKeyFunc(jwtToken *jwt.Token) (interface{}, error) {
231+
func (ah *AppleHandler) tokenKeyFunc(jwtToken *jwt.Token) (any, error) {
232232
if jwtToken == nil {
233233
return nil, fmt.Errorf("failed to call token keyFunc, because token is nil")
234234
}

provider/apple_pubkeys.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ func (aks *appleKeySet) get(kid string) (keys *applePublicKey, err error) {
162162
}
163163

164164
// keyFunc use for JWT verify with specific public key
165-
func (aks *appleKeySet) keyFunc(token *jwt.Token) (interface{}, error) {
165+
func (aks *appleKeySet) keyFunc(token *jwt.Token) (any, error) {
166166

167167
keyID, ok := token.Header["kid"].(string)
168168
if !ok {

provider/apple_pubkeys_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ func TestAppleKeySet_Get(t *testing.T) {
131131

132132
func TestAppleKeySet_KeyFunc(t *testing.T) {
133133

134-
tokenHdr := map[string]interface{}{"kid": "86D88Kf"}
134+
tokenHdr := map[string]any{"kid": "86D88Kf"}
135135
validToken := jwt.Token{Header: tokenHdr}
136136
testKeySet, err := parseAppleJWK([]byte(`{"keys":[{
137137
"kty": "RSA",

provider/apple_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -593,7 +593,7 @@ func prepareAppleOauthTest(t *testing.T, loginPort, authPort int, testToken *str
593593
}
594594
}
595595

596-
func createTestResponseToken(privKey interface{}) (string, error) {
596+
func createTestResponseToken(privKey any) (string, error) {
597597
claims := &jwt.MapClaims{
598598
"iss": "http://go.localhost.test",
599599
"iat": time.Now().Unix(),

provider/custom_server_test.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,8 +103,7 @@ func TestCustomProvider(t *testing.T) {
103103
router.Handle("/auth/customprov/", http.HandlerFunc(s.Handler))
104104
ts := &http.Server{Addr: fmt.Sprintf("127.0.0.1:%d", 8080), Handler: router} //nolint:gosec
105105

106-
ctx, cancel := context.WithCancel(context.Background())
107-
defer cancel()
106+
ctx := t.Context()
108107

109108
go prov.Run(ctx)
110109
go ts.ListenAndServe()

0 commit comments

Comments
 (0)