Created
August 10, 2020 17:30
-
-
Save digitallysavvy/4413ea4496daee61c19f7387e4f3baa6 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 parseRtmParams(c *gin.Context) (uidStr string, expireTimestamp uint32, err error) { | |
// get param values | |
uidStr = c.Param("uid") | |
expireTime := c.DefaultQuery("expiry", "3600") | |
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 | |
// check if string conversion fails | |
return uidStr, expireTimestamp, err | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment