From 0ca109db4ab0b8869a15d388ef9036d9117ec081 Mon Sep 17 00:00:00 2001 From: Matthew Holt Date: Fri, 15 Nov 2019 12:47:38 -0700 Subject: [PATCH] Minor cleanups --- listeners.go | 9 +++------ modules/caddyhttp/fileserver/caddyfile.go | 15 +++++++++++++++ usagepool.go | 17 +++++++++-------- 3 files changed, 27 insertions(+), 14 deletions(-) diff --git a/listeners.go b/listeners.go index 37b4c299f..46446420a 100644 --- a/listeners.go +++ b/listeners.go @@ -52,10 +52,7 @@ func Listen(network, addr string) (net.Listener, error) { } // make sure to start its usage counter at 1 - lnGlobal := &globalListener{ - usage: 1, - ln: ln, - } + lnGlobal := &globalListener{usage: 1, ln: ln} listeners[lnKey] = lnGlobal return &fakeCloseListener{ @@ -271,8 +268,8 @@ type ParsedAddress struct { // JoinHostPort is like net.JoinHostPort, but where the port // is StartPort + offset. -func (l ParsedAddress) JoinHostPort(offset uint) string { - return net.JoinHostPort(l.Host, strconv.Itoa(int(l.StartPort+offset))) +func (pa ParsedAddress) JoinHostPort(offset uint) string { + return net.JoinHostPort(pa.Host, strconv.Itoa(int(pa.StartPort+offset))) } // PortRangeSize returns how many ports are in diff --git a/modules/caddyhttp/fileserver/caddyfile.go b/modules/caddyhttp/fileserver/caddyfile.go index b50c1664d..06540bcb5 100644 --- a/modules/caddyhttp/fileserver/caddyfile.go +++ b/modules/caddyhttp/fileserver/caddyfile.go @@ -83,6 +83,21 @@ func parseCaddyfile(h httpcaddyfile.Helper) (caddyhttp.MiddlewareHandler, error) return &fsrv, nil } +// parseTryFiles parses the try_files directive. It combines a file matcher +// with a rewrite directive, so this is not a standard handler directive. +// A try_files directive has this syntax (notice no matcher tokens accepted): +// +// try_files +// +// and is shorthand for: +// +// matcher:try_files { +// file { +// try_files +// } +// } +// rewrite match:try_files {http.matchers.file.relative}{http.request.uri.query_string} +// func parseTryFiles(h httpcaddyfile.Helper) ([]httpcaddyfile.ConfigValue, error) { if !h.Next() { return nil, h.ArgErr() diff --git a/usagepool.go b/usagepool.go index df69caffc..6fd48f5b4 100644 --- a/usagepool.go +++ b/usagepool.go @@ -25,14 +25,15 @@ import ( // only inserted if they do not already exist. There // are two ways to add values to the pool: // -// 1) LoadOrStore will increment usage and store the -// value immediately if it does not already exist -// 2) LoadOrNew will increment usage and construct the -// value immediately if it does not already exist, -// then store that value in the pool. When the -// constructed value is finally deleted from the -// pool (after its usage reaches 0), it will be -// cleaned up by calling its Destruct method. +// 1) LoadOrStore will increment usage and store the +// value immediately if it does not already exist. +// 2) LoadOrNew will atomically check for existence +// and construct the value immediately if it does +// not already exist, or increment the usage +// otherwise, then store that value in the pool. +// When the constructed value is finally deleted +// from the pool (when its usage reaches 0), it +// will be cleaned up by calling Destruct(). // // The use of LoadOrNew allows values to be created // and reused and finally cleaned up only once, even