Last active
August 13, 2020 19:22
-
-
Save digitallysavvy/30599501c303936ef911aba56a1e227b to your computer and use it in GitHub Desktop.
A template shell for an Agora token server using Golang
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
package main | |
import ( | |
"log" | |
"os" | |
"github.com/AgoraIO-Community/go-tokenbuilder/rtctokenbuilder" | |
"github.com/gin-gonic/gin" | |
) | |
var appID, appCertificate string | |
func main() { | |
appIDEnv, appIDExists := os.LookupEnv("APP_ID") | |
appCertEnv, appCertExists := os.LookupEnv("APP_CERTIFICATE") | |
if !appIDExists || !appCertExists { | |
log.Fatal("FATAL ERROR: ENV not properly configured, check APP_ID and APP_CERTIFICATE") | |
} else { | |
appID = appIDEnv | |
appCertificate = appCertEnv | |
} | |
api := gin.Default() | |
api.GET("/ping", func(c *gin.Context) { | |
c.JSON(200, gin.H{ | |
"message": "pong", | |
}) | |
}) | |
api.GET("rtc/:channelName/:role/:tokenType/:uid/", getRtcToken) | |
api.GET("rtm/:uid/", getRtmToken) | |
api.GET("rte/:channelName/:role/:tokenType/:uid/", getBothTokens) | |
api.Run(":8080") | |
} | |
func getRtcToken(c *gin.Context) { | |
} | |
func getRtmToken(c *gin.Context) { | |
} | |
func getBothTokens(c *gin.Context) { | |
} | |
func parseRtcParams(c *gin.Context) (channelName, tokentype, uidStr string, role rtctokenbuilder.Role, expireTimestamp uint32, err error) { | |
} | |
func parseRtmParams(c *gin.Context) (uidStr string, expireTimestamp uint32, err error) { | |
} | |
func generateRtcToken(channelName, uidStr, tokentype string, role rtctokenbuilder.Role, expireTimestamp uint32) (rtcToken string, err error) { | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment