Skip to content

Instantly share code, notes, and snippets.

@digitallysavvy
Last active August 10, 2020 17:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save digitallysavvy/da589321ac27a392ca11ad3e68805e60 to your computer and use it in GitHub Desktop.
Save digitallysavvy/da589321ac27a392ca11ad3e68805e60 to your computer and use it in GitHub Desktop.
A function that takes the context, extracts the parameters, uses them to generate a token, and uses that token in building the JSON response.
func getRtmToken(c *gin.Context) {
log.Printf("rtm token\n")
// get param values
uidStr, expireTimestamp, err := parseRtmParams(c)
if err != nil {
c.Error(err)
c.AbortWithStatusJSON(400, gin.H{
"message": "Error Generating RTC token: " + err.Error(),
"status": 400,
})
return
}
rtmToken, tokenErr := rtmtokenbuilder.BuildToken(appID, appCertificate, uidStr, rtmtokenbuilder.RoleRtmUser, expireTimestamp)
if tokenErr != nil {
log.Println(err) // token failed to generate
c.Error(err)
errMsg := "Error Generating RTM token: " + tokenErr.Error()
c.AbortWithStatusJSON(400, gin.H{
"error": errMsg,
"status": 400,
})
} else {
log.Println("RTM Token generated")
c.JSON(200, gin.H{
"rtmToken": rtmToken,
})
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment