Skip to content

Commit 84f0eab

Browse files
authored
chore: Enable modernize linter (#392)
Signed-off-by: Oleksandr Redko <oleksandr.red+github@gmail.com>
1 parent 45c8f3f commit 84f0eab

7 files changed

Lines changed: 17 additions & 27 deletions

File tree

.golangci.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ formatters:
44
linters:
55
enable:
66
- misspell
7+
- modernize
78
- revive
89
exclusions:
910
generated: strict

web/cache.go

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,10 +63,7 @@ func (c *cache) makeRoom() {
6363
// the cache is on a long tail, we can save a lot of CPU
6464
// time by doing a whole bunch of deletions now and then
6565
// we won't have to do them again for a while.
66-
numToDelete := len(c.cache) / 10
67-
if numToDelete < 1 {
68-
numToDelete = 1
69-
}
66+
numToDelete := max(len(c.cache)/10, 1)
7067
for deleted := 0; deleted <= numToDelete; deleted++ {
7168
// Go maps are "nondeterministic" not actually random,
7269
// so although we could just chop off the "front" of the

web/cache_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ import (
2323
func TestCacheSize(t *testing.T) {
2424
cache := newCache()
2525
expectedSize := 0
26-
for i := 0; i < 200; i++ {
26+
for i := range 200 {
2727
cache.set(fmt.Sprintf("foo%d", i), true)
2828
expectedSize++
2929
if expectedSize > 100 {

web/handler_test.go

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -75,18 +75,15 @@ func TestBasicAuthCache(t *testing.T) {
7575
start = make(chan struct{})
7676
wg sync.WaitGroup
7777
)
78-
wg.Add(300)
79-
for i := 0; i < 150; i++ {
80-
go func() {
78+
for range 150 {
79+
wg.Go(func() {
8180
<-start
8281
login("alice", "alice123", 200)
83-
wg.Done()
84-
}()
85-
go func() {
82+
})
83+
wg.Go(func() {
8684
<-start
8785
login("alice", "alice1234", 401)
88-
wg.Done()
89-
}()
86+
})
9087
}
9188
close(start)
9289
wg.Wait()

web/landing_page.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
// limitations under the License.
1313

1414
//go:build !genassets
15-
// +build !genassets
1615

1716
//go:generate go run -tags genassets gen_assets.go
1817

web/tls_config.go

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import (
2424
"net/url"
2525
"os"
2626
"path/filepath"
27+
"slices"
2728
"strconv"
2829
"strings"
2930
"time"
@@ -97,10 +98,8 @@ func (t *TLSConfig) VerifyPeerCertificate(rawCerts [][]byte, _ [][]*x509.Certifi
9798
}
9899

99100
for _, sanValue := range sanValues {
100-
for _, allowedSan := range t.ClientAllowedSans {
101-
if sanValue == allowedSan {
102-
return nil
103-
}
101+
if slices.Contains(t.ClientAllowedSans, sanValue) {
102+
return nil
104103
}
105104
}
106105

@@ -440,7 +439,7 @@ func Validate(tlsConfigPath string) error {
440439

441440
type Cipher uint16
442441

443-
func (c *Cipher) UnmarshalYAML(unmarshal func(interface{}) error) error {
442+
func (c *Cipher) UnmarshalYAML(unmarshal func(any) error) error {
444443
var s string
445444
err := unmarshal(&s)
446445
if err != nil {
@@ -455,7 +454,7 @@ func (c *Cipher) UnmarshalYAML(unmarshal func(interface{}) error) error {
455454
return errors.New("unknown cipher: " + s)
456455
}
457456

458-
func (c Cipher) MarshalYAML() (interface{}, error) {
457+
func (c Cipher) MarshalYAML() (any, error) {
459458
return tls.CipherSuiteName((uint16)(c)), nil
460459
}
461460

@@ -468,7 +467,7 @@ var curves = map[string]Curve{
468467
"X25519": (Curve)(tls.X25519),
469468
}
470469

471-
func (c *Curve) UnmarshalYAML(unmarshal func(interface{}) error) error {
470+
func (c *Curve) UnmarshalYAML(unmarshal func(any) error) error {
472471
var s string
473472
err := unmarshal(&s)
474473
if err != nil {
@@ -481,7 +480,7 @@ func (c *Curve) UnmarshalYAML(unmarshal func(interface{}) error) error {
481480
return errors.New("unknown curve: " + s)
482481
}
483482

484-
func (c *Curve) MarshalYAML() (interface{}, error) {
483+
func (c *Curve) MarshalYAML() (any, error) {
485484
for s, curveid := range curves {
486485
if *c == curveid {
487486
return s, nil
@@ -499,7 +498,7 @@ var tlsVersions = map[string]TLSVersion{
499498
"TLS10": (TLSVersion)(tls.VersionTLS10),
500499
}
501500

502-
func (tv *TLSVersion) UnmarshalYAML(unmarshal func(interface{}) error) error {
501+
func (tv *TLSVersion) UnmarshalYAML(unmarshal func(any) error) error {
503502
var s string
504503
err := unmarshal(&s)
505504
if err != nil {
@@ -512,7 +511,7 @@ func (tv *TLSVersion) UnmarshalYAML(unmarshal func(interface{}) error) error {
512511
return errors.New("unknown TLS version: " + s)
513512
}
514513

515-
func (tv *TLSVersion) MarshalYAML() (interface{}, error) {
514+
func (tv *TLSVersion) MarshalYAML() (any, error) {
516515
for s, v := range tlsVersions {
517516
if *tv == v {
518517
return s, nil

web/tls_config_test.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,6 @@
1111
// See the License for the specific language governing permissions and
1212
// limitations under the License.
1313

14-
//go:build go1.14
15-
// +build go1.14
16-
1714
package web
1815

1916
import (

0 commit comments

Comments
 (0)