Created
May 31, 2019 01:51
-
-
Save AlecAivazis/699201ecb8d13ce4da44a6fc2aef5856 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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