Rewrite: Use middleware.Replacer.

Bug fix for regexps starting with '/'.
This commit is contained in:
Abiola Ibrahim
2015-09-20 08:49:55 +01:00
parent 10ab037833
commit 0e039a1868
2 changed files with 20 additions and 33 deletions

View File

@ -3,6 +3,7 @@ package middleware
import (
"net"
"net/http"
"path"
"strconv"
"strings"
"time"
@ -40,6 +41,7 @@ func NewReplacer(r *http.Request, rr *responseRecorder, emptyValue string) Repla
"{host}": r.Host,
"{path}": r.URL.Path,
"{query}": r.URL.RawQuery,
"{frag}": r.URL.Fragment,
"{fragment}": r.URL.Fragment,
"{proto}": r.Proto,
"{remote}": func() string {
@ -63,6 +65,14 @@ func NewReplacer(r *http.Request, rr *responseRecorder, emptyValue string) Repla
"{when}": func() string {
return time.Now().Format(timeFormat)
}(),
"{file}": func() string {
_, file := path.Split(r.URL.Path)
return file
}(),
"{dir}": func() string {
dir, _ := path.Split(r.URL.Path)
return dir
}(),
},
emptyValue: emptyValue,
}