Skip to content

v2.0.0-beta1 with net/context support

Pre-release
Pre-release
Compare
Choose a tag to compare
@elithrar elithrar released this 14 Dec 21:19

The v2.0.0-beta1 will likely be released under a standalone repo—nominally ctxcsrf—at some point in the near future.

BREAKING:

  • Now supports net/context's context.Context interface as the underlying request context, moving away from Goji v1's web.C
  • Broadly compatible with any application that supports the goji.Handler interface, which simply requires a ServeHTTPC(context.Context, http.ResponseWriter, *http.Request) method.
  • ErrorHandler now accepts a goji.Handler
  • Removed support for Go 1.4

Most of these changes align with Goji v2, which embraces context.Context in full.

HOW-TO:

The major changes you'll need to make in your application:

// Supports this signature if you cast it to a goji.HandlerFunc, or supply a `ServeHTTPC` method on your type
- func(web.C, http.ResponseWriter, *http.Request)
+ func(context.Context, http.ResponseWriter, *http.Request)

// Change from web.C to context.Context when retrieving tokens
- csrf.Token(c, r)
+ csrf.Token(ctx, r)

// If you're using Goji, apply the middleware to a context-aware method
- mux.Use(csrf.Protect([]byte(key)))
+ mux.UseC(csrf.Protect([]byte(key)))