Skip to content

Commit

Permalink
Prefixing context methods with "ctx".
Browse files Browse the repository at this point in the history
Name like "setToken()" isn't really clear in this case.
  • Loading branch information
justinas committed Aug 24, 2013
1 parent bfb8713 commit 2fd1bf4
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 13 deletions.
4 changes: 2 additions & 2 deletions context.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ func Reason(req *http.Request) error {
return ctx.reason
}

func setToken(req *http.Request, token string) {
func ctxSetToken(req *http.Request, token string) {
cmMutex.Lock()
defer cmMutex.Unlock()

Expand All @@ -69,7 +69,7 @@ func setToken(req *http.Request, token string) {
ctx.token = token
}

func setReason(req *http.Request, reason error) {
func ctxSetReason(req *http.Request, reason error) {
cmMutex.Lock()
defer cmMutex.Unlock()

Expand Down
20 changes: 10 additions & 10 deletions context_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ import (
func TestSetsReasonCorrectly(t *testing.T) {
req := dummyGet()

// set token first, as it's required for setReason
setToken(req, "abcdef")
// set token first, as it's required for ctxSetReason
ctxSetToken(req, "abcdef")

err := errors.New("universe imploded")
setReason(req, err)
ctxSetReason(req, err)

got := contextMap[req].reason

Expand All @@ -28,17 +28,17 @@ func TestSettingReasonFailsWithoutContext(t *testing.T) {
defer func() {
r := recover()
if r == nil {
t.Error("setReason() didn't panic on no context")
t.Error("ctxSetReason() didn't panic on no context")
}
}()

setReason(req, err)
ctxSetReason(req, err)
}

func TestSetsTokenCorrectly(t *testing.T) {
req := dummyGet()
token := "abcdef"
setToken(req, token)
ctxSetToken(req, token)

got := contextMap[req].token

Expand All @@ -56,7 +56,7 @@ func TestGetsTokenCorrectly(t *testing.T) {
}

intended := "abcdef"
setToken(req, intended)
ctxSetToken(req, intended)

token = Token(req)
if token != "abcdef" {
Expand All @@ -72,11 +72,11 @@ func TestGetsReasonCorrectly(t *testing.T) {
t.Errorf("Reason hasn't been set yet, but it's not nil, it's %v", reason)
}

// again, needed for setReason() to work
setToken(req, "dummy")
// again, needed for ctxSetReason() to work
ctxSetToken(req, "dummy")

intended := errors.New("universe imploded")
setReason(req, intended)
ctxSetReason(req, intended)

reason = Reason(req)
if reason != intended {
Expand Down
2 changes: 1 addition & 1 deletion handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ func (h *CSRFHandler) RegenerateToken(w http.ResponseWriter, r *http.Request) st

http.SetCookie(w, &cookie)

setToken(r, token)
ctxSetToken(r, token)

return token
}
Expand Down

0 comments on commit 2fd1bf4

Please sign in to comment.