Skip to content

Commit 1337822

Browse files
committed
Upgrade GO version to v1.22, CI lint version to v.1.50 and YAEGI version to v0.14.2
1 parent f689a86 commit 1337822

File tree

6 files changed

+99
-71
lines changed

6 files changed

+99
-71
lines changed

.github/workflows/go-cross.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ jobs:
1010

1111
strategy:
1212
matrix:
13-
go-version: [1.19, 1.x]
13+
go-version: [1.22, 1.x]
1414
os: [ubuntu-latest, macos-latest, windows-latest]
1515

1616
steps:

.github/workflows/main.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@ jobs:
1313
name: Main Process
1414
runs-on: ubuntu-latest
1515
env:
16-
GO_VERSION: 1.19
17-
GOLANGCI_LINT_VERSION: v1.50.0
18-
YAEGI_VERSION: v0.14.2
16+
GO_VERSION: 1.22
17+
GOLANGCI_LINT_VERSION: v1.58.1
18+
YAEGI_VERSION: v0.16.1
1919
CGO_ENABLED: 0
2020
defaults:
2121
run:

.golangci.yml

Lines changed: 10 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,19 @@
11
# inspired by: https://github.com/golangci/golangci-lint/blob/master/.golangci.yml
22

33
run:
4-
go: "1.18"
4+
go: "1.22"
55

66
linters-settings:
77
# dupl:
88
# threshold: 100
99
funlen:
1010
lines: 100
1111
statements: 50
12-
golint:
13-
min-confidence: 0
1412
lll:
1513
line-length: 125
1614
goconst:
1715
min-len: 2
18-
min-occurences: 2
16+
min-occurrences: 3
1917
misspell:
2018
locale: US
2119

@@ -26,50 +24,45 @@ linters:
2624
# - bidichk
2725
# - bodyclose
2826
# - contextcheck
29-
- deadcode
30-
- depguard
27+
# - depguard
3128
- dogsled
3229
# - dupl
3330
# - durationcheck
3431
- errcheck
3532
# - errname
36-
- exportloopref
3733
- funlen
3834
- gochecknoinits
3935
- goconst
4036
- gocritic
4137
- gocyclo
4238
- gofmt
4339
- goimports
44-
- gomnd
40+
- mnd
4541
- goprintffuncname
4642
- gosec
4743
- gosimple
4844
- govet
49-
# - ifshort
50-
# - importas
45+
- importas
5146
- ineffassign
5247
- lll
53-
# - makezero
48+
- makezero
5449
- misspell
5550
- nakedret
56-
# - nilerr
51+
- nilerr
5752
# - nilnil
5853
# - noctx
5954
- nolintlint
60-
# - predeclared
61-
# - revive
55+
- predeclared
56+
- revive
6257
- staticcheck
63-
- structcheck
6458
- stylecheck
6559
# - tagliatelle
6660
# - thelper
6761
- typecheck
6862
- unconvert
6963
- unparam
7064
- unused
71-
- varcheck
72-
# - wastedassign
65+
- wastedassign
7366
- whitespace
7467

7568
# don't enable:

geoblock.go

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"context"
66
"fmt"
77
"io"
8+
"io/fs"
89
"log"
910
"net"
1011
"net/http"
@@ -24,6 +25,7 @@ const (
2425
unknownCountryCode = "AA"
2526
countryCodeLength = 2
2627
defaultDeniedRequestHTTPStatusCode = 403
28+
filePermissions = fs.FileMode(0666)
2729
)
2830

2931
var (
@@ -110,11 +112,11 @@ func New(ctx context.Context, next http.Handler, config *Config, name string) (h
110112
}
111113

112114
// set default HTTP status code for denied requests if non other is supplied
113-
deniedRequestHttpStatusCode, err := getHttpStatusCodeDeniedRequest(config.HTTPStatusCodeDeniedRequest)
115+
deniedRequestHTTPStatusCode, err := getHTTPStatusCodeDeniedRequest(config.HTTPStatusCodeDeniedRequest)
114116
if err != nil {
115117
return nil, err
116118
}
117-
config.HTTPStatusCodeDeniedRequest = deniedRequestHttpStatusCode
119+
config.HTTPStatusCodeDeniedRequest = deniedRequestHTTPStatusCode
118120

119121
// build allowed IP and IP ranges lists
120122
allowedIPAddresses, allowedIPRanges := parseAllowedIPAddresses(config.AllowedIPAddresses, infoLogger)
@@ -208,12 +210,12 @@ func (a *GeoBlock) allowDenyIPAddress(requestIPAddr *net.IP, req *http.Request)
208210
infoLogger.Printf("%s: request allowed [%s] since local IP addresses are allowed", a.name, requestIPAddr)
209211
}
210212
return true
211-
} else {
212-
if a.logLocalRequests {
213-
infoLogger.Printf("%s: request denied [%s] since local IP addresses are denied", a.name, requestIPAddr)
214-
}
215-
return false
216213
}
214+
215+
if a.logLocalRequests {
216+
infoLogger.Printf("%s: request denied [%s] since local IP addresses are denied", a.name, requestIPAddr)
217+
}
218+
return false
217219
}
218220

219221
// check if the request IP address is explicitly allowed
@@ -235,7 +237,7 @@ func (a *GeoBlock) allowDenyIPAddress(requestIPAddr *net.IP, req *http.Request)
235237
}
236238

237239
// check if the GeoIP database contains an entry for the request IP address
238-
allowed, countryCode := a.allowDenyCachedRequestIp(requestIPAddr, req)
240+
allowed, countryCode := a.allowDenyCachedRequestIP(requestIPAddr, req)
239241

240242
if a.addCountryHeader && len(countryCode) > 0 {
241243
req.Header.Set(countryHeader, countryCode)
@@ -244,7 +246,7 @@ func (a *GeoBlock) allowDenyIPAddress(requestIPAddr *net.IP, req *http.Request)
244246
return allowed
245247
}
246248

247-
func (a *GeoBlock) allowDenyCachedRequestIp(requestIPAddr *net.IP, req *http.Request) (bool, string) {
249+
func (a *GeoBlock) allowDenyCachedRequestIP(requestIPAddr *net.IP, req *http.Request) (bool, string) {
248250
ipAddressString := requestIPAddr.String()
249251
cacheEntry, ok := a.database.Get(ipAddressString)
250252

@@ -492,7 +494,7 @@ func isPrivateIP(ip net.IP, privateIPBlocks []*net.IPNet) bool {
492494
return false
493495
}
494496

495-
func getHttpStatusCodeDeniedRequest(code int) (int, error) {
497+
func getHTTPStatusCodeDeniedRequest(code int) (int, error) {
496498
if code != 0 {
497499
// check if given status code is valid
498500
if len(http.StatusText(code)) == 0 {
@@ -567,7 +569,7 @@ func initializeLogFile(logFilePath string, logger *log.Logger) (*os.File, error)
567569
return nil, fmt.Errorf("folder is not writable: %s", logFilePath)
568570
}
569571

570-
logFile, err := os.OpenFile(logFilePath, os.O_RDWR|os.O_CREATE|os.O_APPEND, 0666)
572+
logFile, err := os.OpenFile(logFilePath, os.O_RDWR|os.O_CREATE|os.O_APPEND, filePermissions)
571573
if err != nil {
572574
logger.Printf("Failed to open log file: %v\n", err)
573575
return nil, err

0 commit comments

Comments
 (0)