Skip to content

Commit 397e68d

Browse files
author
pyed
committed
gofmt: minor changes
1 parent daf6d3d commit 397e68d

2 files changed

Lines changed: 18 additions & 17 deletions

File tree

README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,22 +30,22 @@ ipfilter / {
3030
}
3131
```
3232
`caddy` will block any client IP that appears as a file name in the
33-
*blacklisted* directory. A relative pathname is relative to the CWD when
33+
`blacklisted` directory. A relative pathname is relative to the CWD when
3434
`caddy` is started. When putting the blacklisted directory in the web
3535
server document tree you should also add an `internal` directive to
3636
ensure those files are not visible via HTTP GET requests. For example,
3737
`internal /blacklisted/`. You can also specify an absolute pathname to
3838
locate the blacklist directory outside the document tree.
3939

4040
You can create the file in the root of the blacklist directory. This is
41-
known as using a "flat" namespace. For example, *blacklisted/127.0.0.1*
42-
or *blacklisted/2601:647:4601:fa93:1865:4b6c:d055:3f3*. However,
41+
known as using a "flat" namespace. For example, `blacklisted/127.0.0.1`
42+
or `blacklisted/2601:647:4601:fa93:1865:4b6c:d055:3f3`. However,
4343
putting thousands of files in a single directory may cause
4444
poor performance of the lookup function. So you can also,
4545
and should, use a "sharded" namespace. This involves creating
4646
the file in a subdirectory based on the first two components
47-
of the address. For example, *blacklisted/127/0/127.0.0.1* or
48-
*blacklisted/2601/647/2601:647:4601:fa93:1865:4b6c:d055:3f3*.
47+
of the address. For example, `blacklisted/127/0/127.0.0.1` or
48+
`blacklisted/2601/647/2601:647:4601:fa93:1865:4b6c:d055:3f3`.
4949

5050
Note that you can also whitelist IP addresses using this mechanism by
5151
specifying `rule allow`. This may be useful when it follows a more general

ipfilter.go

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,7 @@ func (ipf IPFilter) ShouldAllow(path IPPath, r *http.Request) (bool, string, err
197197
return allow, scopeMatched, nil
198198
}
199199

200+
// PrefixDirBlocked takes an IP and a path and decides to allow or block based on prefix_dir.
200201
func (ipf IPFilter) PrefixDirBlocked(clientIP net.IP, path IPPath) bool {
201202
if path.PrefixDir == "" {
202203
return false
@@ -205,8 +206,8 @@ func (ipf IPFilter) PrefixDirBlocked(clientIP net.IP, path IPPath) bool {
205206
fname := clientIP.String()
206207

207208
// Check the "flat" namespace.
208-
blacklist_path := filepath.Join(path.PrefixDir, fname)
209-
if _, err := os.Stat(blacklist_path); err == nil {
209+
blacklistPath := filepath.Join(path.PrefixDir, fname)
210+
if _, err := os.Stat(blacklistPath); err == nil {
210211
return true
211212
}
212213

@@ -222,8 +223,8 @@ func (ipf IPFilter) PrefixDirBlocked(clientIP net.IP, path IPPath) bool {
222223
return false
223224
}
224225
}
225-
blacklist_path = filepath.Join(path.PrefixDir, c[0], c[1], fname)
226-
if _, err := os.Stat(blacklist_path); err == nil {
226+
blacklistPath = filepath.Join(path.PrefixDir, c[0], c[1], fname)
227+
if _, err := os.Stat(blacklistPath); err == nil {
227228
return true
228229
}
229230

@@ -323,7 +324,7 @@ func parseIP(ip string) ([]*net.IPNet, error) {
323324
// ipfilterParseSingle parses a single ipfilter {} block from the caddy config.
324325
func ipfilterParseSingle(config *IPFConfig, c *caddy.Controller) (IPPath, error) {
325326
var cPath IPPath
326-
rule_type_specified := false
327+
ruleTypeSpecified := false
327328

328329
// Get PathScopes
329330
cPath.PathScopes = c.RemainingArgs()
@@ -342,7 +343,7 @@ func ipfilterParseSingle(config *IPFConfig, c *caddy.Controller) (IPPath, error)
342343
if !c.NextArg() {
343344
return cPath, c.ArgErr()
344345
}
345-
if rule_type_specified {
346+
if ruleTypeSpecified {
346347
return cPath, c.Err("ipfilter: Only one 'rule' directive per block allowed")
347348
}
348349

@@ -352,7 +353,7 @@ func ipfilterParseSingle(config *IPFConfig, c *caddy.Controller) (IPPath, error)
352353
} else if rule != "allow" {
353354
return cPath, c.Err("ipfilter: Rule should be 'block' or 'allow'")
354355
}
355-
rule_type_specified = true
356+
ruleTypeSpecified = true
356357
case "database":
357358
if !c.NextArg() {
358359
return cPath, c.ArgErr()
@@ -408,16 +409,16 @@ func ipfilterParseSingle(config *IPFConfig, c *caddy.Controller) (IPPath, error)
408409
}
409410

410411
// Verify the blacklist path prefix exists and is a directory.
411-
prefix_dir := c.Val()
412-
if statb, err := os.Stat(prefix_dir); os.IsNotExist(err) || !statb.IsDir() {
413-
return cPath, c.Err("ipfilter: No such blacklist prefix dir: " + prefix_dir)
412+
prefixDir := c.Val()
413+
if statb, err := os.Stat(prefixDir); os.IsNotExist(err) || !statb.IsDir() {
414+
return cPath, c.Err("ipfilter: No such blacklist prefix dir: " + prefixDir)
414415
}
415416

416-
cPath.PrefixDir = prefix_dir
417+
cPath.PrefixDir = prefixDir
417418
}
418419
}
419420

420-
if !rule_type_specified {
421+
if !ruleTypeSpecified {
421422
return cPath, c.Err("ipfilter: There must be one 'rule' directive per block")
422423
}
423424
return cPath, nil

0 commit comments

Comments
 (0)