Skip to content

Instantly share code, notes, and snippets.

@AlecAivazis
Created May 31, 2019 01:51
Show Gist options
  • Save AlecAivazis/699201ecb8d13ce4da44a6fc2aef5856 to your computer and use it in GitHub Desktop.
Save AlecAivazis/699201ecb8d13ce4da44a6fc2aef5856 to your computer and use it in GitHub Desktop.
var forwardUserID = gateway.RequestMiddleware(func(r *http.Request) error {
// the initial context of the request is set to match the one we modified earlier
// we are safe to extract the value we saved in context
if userID := r.Context().Value("user-id"); userID != nil {
// set the header with the value we pulled out of context
r.Header.Set("USER_ID", userID.(string))
}
// there was no error
return nil
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment