5
5
"context"
6
6
"fmt"
7
7
"io"
8
+ "io/fs"
8
9
"log"
9
10
"net"
10
11
"net/http"
@@ -110,11 +111,11 @@ func New(ctx context.Context, next http.Handler, config *Config, name string) (h
110
111
}
111
112
112
113
// set default HTTP status code for denied requests if non other is supplied
113
- deniedRequestHttpStatusCode , err := getHttpStatusCodeDeniedRequest (config .HTTPStatusCodeDeniedRequest )
114
+ deniedRequestHTTPStatusCode , err := getHTTPStatusCodeDeniedRequest (config .HTTPStatusCodeDeniedRequest )
114
115
if err != nil {
115
116
return nil , err
116
117
}
117
- config .HTTPStatusCodeDeniedRequest = deniedRequestHttpStatusCode
118
+ config .HTTPStatusCodeDeniedRequest = deniedRequestHTTPStatusCode
118
119
119
120
// build allowed IP and IP ranges lists
120
121
allowedIPAddresses , allowedIPRanges := parseAllowedIPAddresses (config .AllowedIPAddresses , infoLogger )
@@ -235,7 +236,7 @@ func (a *GeoBlock) allowDenyIPAddress(requestIPAddr *net.IP, req *http.Request)
235
236
}
236
237
237
238
// check if the GeoIP database contains an entry for the request IP address
238
- allowed , countryCode := a .allowDenyCachedRequestIp (requestIPAddr , req )
239
+ allowed , countryCode := a .allowDenyCachedRequestIP (requestIPAddr , req )
239
240
240
241
if a .addCountryHeader && len (countryCode ) > 0 {
241
242
req .Header .Set (countryHeader , countryCode )
@@ -244,7 +245,7 @@ func (a *GeoBlock) allowDenyIPAddress(requestIPAddr *net.IP, req *http.Request)
244
245
return allowed
245
246
}
246
247
247
- func (a * GeoBlock ) allowDenyCachedRequestIp (requestIPAddr * net.IP , req * http.Request ) (bool , string ) {
248
+ func (a * GeoBlock ) allowDenyCachedRequestIP (requestIPAddr * net.IP , req * http.Request ) (bool , string ) {
248
249
ipAddressString := requestIPAddr .String ()
249
250
cacheEntry , ok := a .database .Get (ipAddressString )
250
251
@@ -492,7 +493,7 @@ func isPrivateIP(ip net.IP, privateIPBlocks []*net.IPNet) bool {
492
493
return false
493
494
}
494
495
495
- func getHttpStatusCodeDeniedRequest (code int ) (int , error ) {
496
+ func getHTTPStatusCodeDeniedRequest (code int ) (int , error ) {
496
497
if code != 0 {
497
498
// check if given status code is valid
498
499
if len (http .StatusText (code )) == 0 {
@@ -567,7 +568,8 @@ func initializeLogFile(logFilePath string, logger *log.Logger) (*os.File, error)
567
568
return nil , fmt .Errorf ("folder is not writable: %s" , logFilePath )
568
569
}
569
570
570
- logFile , err := os .OpenFile (logFilePath , os .O_RDWR | os .O_CREATE | os .O_APPEND , 0666 )
571
+ filePermissions := fs .FileMode (0666 )
572
+ logFile , err := os .OpenFile (logFilePath , os .O_RDWR | os .O_CREATE | os .O_APPEND , filePermissions )
571
573
if err != nil {
572
574
logger .Printf ("Failed to open log file: %v\n " , err )
573
575
return nil , err
0 commit comments