Last active
August 10, 2020 17:36
-
-
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.
This file contains 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
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