Created
November 25, 2013 16:43
-
-
Save tobz/7644327 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
// Make sure the caller actually has the authority to call these methods. | |
handler.MapBefore([]string{"GET", "DELETE"}, "token", func(c context.Context) (error) { | |
// TODO: Figure out if this is the right way to preempt processing of a request. | |
// Check to see if this token is a supertoken. | |
if token, ok := c.Data()["Token"].(*ManagedToken); !ok { | |
goweb.API.RespondWithError(c, 500, "Internal authorization failure") | |
return fmt.Errorf("Failed to extract authorization token from request - this is bad/not right.") | |
} else { | |
if !token.Super { | |
goweb.API.RespondWithError(c, 401, "You are not authorized to call these methods.") | |
return fmt.Errorf("Request tried to execute supertoken-level methods without supertoken") | |
} | |
return nil | |
} | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment