diff --git a/doc.go b/doc.go index 3bc9eec..20ae2cb 100644 --- a/doc.go +++ b/doc.go @@ -161,7 +161,5 @@ To access this `Context` variable, the code is very simple: return nil } - */ +*/ package rye - - diff --git a/example/rye_example.go b/example/rye_example.go index 5cb5e8e..549d026 100644 --- a/example/rye_example.go +++ b/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" @@ -59,7 +59,7 @@ func main() { []rye.Handler{ stashContextHandler, logContextHandler, - })).Methods("GET") + })).Methods("GET") log.Infof("API server listening on %v", "localhost:8181") @@ -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 { @@ -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 } @@ -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 -} \ No newline at end of file +} diff --git a/example_overall_test.go b/example_overall_test.go index 0239b6d..e3b050e 100644 --- a/example_overall_test.go +++ b/example_overall_test.go @@ -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 { @@ -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 } @@ -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 -} \ No newline at end of file +} diff --git a/middleware_cors.go b/middleware_cors.go index a07e834..8e1fcb2 100644 --- a/middleware_cors.go +++ b/middleware_cors.go @@ -1,11 +1,9 @@ - package rye import ( "net/http" ) - const ( // CORS Specific constants DEFAULT_CORS_ALLOW_ORIGIN = "*" diff --git a/middleware_jwt.go b/middleware_jwt.go index e32ca2e..7487c3e 100644 --- a/middleware_jwt.go +++ b/middleware_jwt.go @@ -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} } diff --git a/rye.go b/rye.go index bc99ed5..2145feb 100644 --- a/rye.go +++ b/rye.go @@ -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. diff --git a/rye_test.go b/rye_test.go index 0e6ab08..dd3fb7d 100644 --- a/rye_test.go +++ b/rye_test.go @@ -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")) }) @@ -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} }