Last active
August 10, 2020 16:29
-
-
Save digitallysavvy/f5466530c73de45bf49a2b5ba535364c to your computer and use it in GitHub Desktop.
A function that takes the context, extracts and returns the parameters.
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 parseRtcParams(c *gin.Context) (channelName, tokentype, uidStr string, role rtctokenbuilder.Role, expireTimestamp uint32, err error) { | |
// get param values | |
channelName = c.Param("channelName") | |
roleStr := c.Param("role") | |
tokentype = c.Param("tokentype") | |
uidStr = c.Param("uid") | |
expireTime := c.DefaultQuery("expiry", "3600") | |
if roleStr == "publisher" { | |
role = rtctokenbuilder.RolePublisher | |
} else { | |
role = rtctokenbuilder.RoleSubscriber | |
} | |
expireTime64, parseErr := strconv.ParseUint(expireTime, 10, 64) | |
if parseErr != nil { | |
// if string conversion fails return an error | |
err = fmt.Errorf("failed to parse expireTime: %s, causing error: %s", expireTime, parseErr) | |
} | |
// set timestamps | |
expireTimeInSeconds := uint32(expireTime64) | |
currentTimestamp := uint32(time.Now().UTC().Unix()) | |
expireTimestamp = currentTimestamp + expireTimeInSeconds | |
return channelName, tokentype, uidStr, role, expireTimestamp, err | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment