Skip to content

Instantly share code, notes, and snippets.

@kentquirk
Created October 9, 2015 23:03
Show Gist options
  • Save kentquirk/60b46ed7a931194cf20b to your computer and use it in GitHub Desktop.
Save kentquirk/60b46ed7a931194cf20b to your computer and use it in GitHub Desktop.
Check token Golang middleware
// ChkTok is middleware that validates that the required
// security token is present.
func ChkTok(handler http.HandlerFunc) http.HandlerFunc {
return func(rw http.ResponseWriter, req *http.Request) {
sessionid := req.Header.Get(AUTHTOKEN)
if sessionid == "" {
util.WriteNewWebError(rw, http.StatusForbidden, "U-107", "x-anet-token is required.")
return
}
handler(rw, req)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment