Rename a bunch of "Make" functions to "New"

Also rename some to other names that make better reading.  There are still a
bunch of "make" functions but they do things like assemble a string from parts
or build an array of things.  It seemed that "make" there seemed fine.  "New"
is for "constructors".
This commit is contained in:
Tim Hockin
2014-08-20 21:27:19 -07:00
parent 953cd923f1
commit 0f97a73c1b
33 changed files with 217 additions and 217 deletions

View File

@@ -32,7 +32,7 @@ import (
// Intended to wrap calls to your ServeMux.
func Handler(delegate http.Handler, pred StacktracePred) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) {
defer MakeLogged(req, &w).StacktraceWhen(pred).Log()
defer NewLogged(req, &w).StacktraceWhen(pred).Log()
delegate.ServeHTTP(w, req)
})
}
@@ -59,11 +59,11 @@ func DefaultStacktracePred(status int) bool {
return status < http.StatusOK || status >= http.StatusBadRequest
}
// MakeLogged turns a normal response writer into a logged response writer.
// NewLogged turns a normal response writer into a logged response writer.
//
// Usage:
//
// defer MakeLogged(req, &w).StacktraceWhen(StatusIsNot(200, 202)).Log()
// defer NewLogged(req, &w).StacktraceWhen(StatusIsNot(200, 202)).Log()
//
// (Only the call to Log() is defered, so you can set everything up in one line!)
//
@@ -71,10 +71,10 @@ func DefaultStacktracePred(status int) bool {
// through the logger.
//
// Use LogOf(w).Addf(...) to log something along with the response result.
func MakeLogged(req *http.Request, w *http.ResponseWriter) *respLogger {
func NewLogged(req *http.Request, w *http.ResponseWriter) *respLogger {
if _, ok := (*w).(*respLogger); ok {
// Don't double-wrap!
panic("multiple MakeLogged calls!")
panic("multiple NewLogged calls!")
}
rl := &respLogger{
startTime: time.Now(),
@@ -87,7 +87,7 @@ func MakeLogged(req *http.Request, w *http.ResponseWriter) *respLogger {
}
// LogOf returns the logger hiding in w. Panics if there isn't such a logger,
// because MakeLogged() must have been previously called for the log to work.
// because NewLogged() must have been previously called for the log to work.
func LogOf(w http.ResponseWriter) *respLogger {
if rl, ok := w.(*respLogger); ok {
return rl

View File

@@ -65,19 +65,19 @@ func TestStatusIsNot(t *testing.T) {
}
}
func TestMakeLogged(t *testing.T) {
func TestNewLogged(t *testing.T) {
req, err := http.NewRequest("GET", "http://example.com", nil)
if err != nil {
t.Errorf("Unexpected error: %v", err)
}
handler := func(w http.ResponseWriter, r *http.Request) {
MakeLogged(req, &w)
NewLogged(req, &w)
defer func() {
if r := recover(); r == nil {
t.Errorf("Expected MakeLogged to panic")
t.Errorf("Expected NewLogged to panic")
}
}()
MakeLogged(req, &w)
NewLogged(req, &w)
}
w := httptest.NewRecorder()
handler(w, req)
@@ -93,7 +93,7 @@ func TestLogOf(t *testing.T) {
handler := func(w http.ResponseWriter, r *http.Request) {
var want *respLogger
if makeLogger {
want = MakeLogged(req, &w)
want = NewLogged(req, &w)
} else {
defer func() {
if r := recover(); r == nil {
@@ -121,7 +121,7 @@ func TestUnlogged(t *testing.T) {
handler := func(w http.ResponseWriter, r *http.Request) {
want := w
if makeLogger {
MakeLogged(req, &w)
NewLogged(req, &w)
}
got := Unlogged(w)
if want != got {