Skip to content

Commit

Permalink
go fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
talpert committed Dec 6, 2016
1 parent 3dc49fe commit d5bc733
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 26 deletions.
4 changes: 1 addition & 3 deletions doc.go
Expand Up @@ -161,7 +161,5 @@ To access this `Context` variable, the code is very simple:
return nil
}
*/
*/
package rye


16 changes: 8 additions & 8 deletions example/rye_example.go
@@ -1,10 +1,10 @@
package main

import (
"context"
"errors"
"fmt"
"net/http"
"context"

"github.com/InVisionApp/rye"
log "github.com/Sirupsen/logrus"
Expand Down Expand Up @@ -59,7 +59,7 @@ func main() {
[]rye.Handler{
stashContextHandler,
logContextHandler,
})).Methods("GET")
})).Methods("GET")

log.Infof("API server listening on %v", "localhost:8181")

Expand Down Expand Up @@ -104,19 +104,19 @@ func stashContextHandler(rw http.ResponseWriter, r *http.Request) *rye.Response
toContext := r.URL.Query().Get("ctx")

if toContext != "" {
log.Infof("Adding `query-string-ctx` to request.Context(). Val: %v",toContext)
log.Infof("Adding `query-string-ctx` to request.Context(). Val: %v", toContext)
} else {
log.Infof("Adding default `query-string-ctx` value to context")
toContext = "No value added. Add querystring param `ctx` with a value to get it mirrored through context."
}

// Create a NEW context
ctx = context.WithValue(ctx,"query-string-ctx",toContext)
ctx = context.WithValue(ctx, "query-string-ctx", toContext)

// Return that in the Rye response
// Rye will add it to the Request to
// pass to the next middleware
return &rye.Response{Context:ctx}
return &rye.Response{Context: ctx}
}

func logContextHandler(rw http.ResponseWriter, r *http.Request) *rye.Response {
Expand All @@ -126,7 +126,7 @@ func logContextHandler(rw http.ResponseWriter, r *http.Request) *rye.Response {
fromContext := r.Context().Value("query-string-ctx")

// Reflect that on the http response
fmt.Fprintf(rw,"Here's the `ctx` query string value you passed. Pulled from context: %v",fromContext)
fmt.Fprintf(rw, "Here's the `ctx` query string value you passed. Pulled from context: %v", fromContext)
return nil
}

Expand All @@ -136,7 +136,7 @@ func getJwtFromContextHandler(rw http.ResponseWriter, r *http.Request) *rye.Resp

jwt := r.Context().Value(rye.CONTEXT_JWT)
if jwt != nil {
fmt.Fprintf(rw, "JWT found in Context: %v",jwt)
fmt.Fprintf(rw, "JWT found in Context: %v", jwt)
}
return nil
}
}
12 changes: 6 additions & 6 deletions example_overall_test.go
Expand Up @@ -104,19 +104,19 @@ func stashContextHandler(rw http.ResponseWriter, r *http.Request) *rye.Response
toContext := r.URL.Query().Get("ctx")

if toContext != "" {
log.Infof("Adding `query-string-ctx` to request.Context(). Val: %v",toContext)
log.Infof("Adding `query-string-ctx` to request.Context(). Val: %v", toContext)
} else {
log.Infof("Adding default `query-string-ctx` value to context")
toContext = "No value added. Add querystring param `ctx` with a value to get it mirrored through context."
}

// Create a NEW context
ctx = context.WithValue(ctx,"query-string-ctx",toContext)
ctx = context.WithValue(ctx, "query-string-ctx", toContext)

// Return that in the Rye response
// Rye will add it to the Request to
// pass to the next middleware
return &rye.Response{Context:ctx}
return &rye.Response{Context: ctx}
}

func logContextHandler(rw http.ResponseWriter, r *http.Request) *rye.Response {
Expand All @@ -126,7 +126,7 @@ func logContextHandler(rw http.ResponseWriter, r *http.Request) *rye.Response {
fromContext := r.Context().Value("query-string-ctx")

// Reflect that on the http response
fmt.Fprintf(rw,"Here's the `ctx` query string value you passed. Pulled from context: %v",fromContext)
fmt.Fprintf(rw, "Here's the `ctx` query string value you passed. Pulled from context: %v", fromContext)
return nil
}

Expand All @@ -136,7 +136,7 @@ func getJwtFromContextHandler(rw http.ResponseWriter, r *http.Request) *rye.Resp

jwt := r.Context().Value(rye.CONTEXT_JWT)
if jwt != nil {
fmt.Fprintf(rw, "JWT found in Context: %v",jwt)
fmt.Fprintf(rw, "JWT found in Context: %v", jwt)
}
return nil
}
}
2 changes: 0 additions & 2 deletions middleware_cors.go
@@ -1,11 +1,9 @@

package rye

import (
"net/http"
)


const (
// CORS Specific constants
DEFAULT_CORS_ALLOW_ORIGIN = "*"
Expand Down
4 changes: 2 additions & 2 deletions middleware_jwt.go
Expand Up @@ -86,7 +86,7 @@ func (j *jwtVerify) handle(rw http.ResponseWriter, req *http.Request) *Response
}
}

ctx := context.WithValue(req.Context(),CONTEXT_JWT,j.token)
ctx := context.WithValue(req.Context(), CONTEXT_JWT, j.token)

return &Response{Context:ctx}
return &Response{Context: ctx}
}
2 changes: 1 addition & 1 deletion rye.go
Expand Up @@ -43,7 +43,7 @@ type Response struct {
Err error
StatusCode int
StopExecution bool
Context context.Context
Context context.Context
}

// Error bubbles a response error providing an implementation of the Error interface.
Expand Down
8 changes: 4 additions & 4 deletions rye_test.go
Expand Up @@ -130,9 +130,9 @@ var _ = Describe("Rye", func() {
})

Context("when a handler returns a response with Context", func() {
It("should add that new context to the next passed request", func(){
h := mwHandler.Handle([]Handler{contextHandler,checkContextHandler})
h.ServeHTTP(response,request)
It("should add that new context to the next passed request", func() {
h := mwHandler.Handle([]Handler{contextHandler, checkContextHandler})
h.ServeHTTP(response, request)

Expect(os.Getenv(RYE_TEST_HANDLER_ENV_VAR)).To(Equal("1"))
})
Expand Down Expand Up @@ -199,7 +199,7 @@ var _ = Describe("Rye", func() {
})

func contextHandler(rw http.ResponseWriter, r *http.Request) *Response {
ctx := context.WithValue(r.Context(),"test-val","exists")
ctx := context.WithValue(r.Context(), "test-val", "exists")
return &Response{Context: ctx}
}

Expand Down

0 comments on commit d5bc733

Please sign in to comment.