本文整理匯總了Golang中github.com/TF2Stadium/wsevent.Server.NewClient方法的典型用法代碼示例。如果您正苦於以下問題:Golang Server.NewClient方法的具體用法?Golang Server.NewClient怎麽用?Golang Server.NewClient使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/TF2Stadium/wsevent.Server
的用法示例。
在下文中一共展示了Server.NewClient方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: SetupHTTPRoutes
func SetupHTTPRoutes(server *wsevent.Server, noauth *wsevent.Server) {
http.HandleFunc("/", controllers.MainHandler)
http.HandleFunc("/openidcallback", controllers.LoginCallbackHandler)
http.HandleFunc("/startLogin", controllers.LoginHandler)
http.HandleFunc("/logout", controllers.LogoutHandler)
if config.Constants.MockupAuth {
http.HandleFunc("/startMockLogin/", controllers.MockLoginHandler)
}
http.HandleFunc("/websocket/", func(w http.ResponseWriter, r *http.Request) {
if config.Constants.SteamIDWhitelist != "" {
session, err := chelpers.GetSessionHTTP(r)
allowed := true
if err == nil {
steamid, ok := session.Values["steam_id"]
if !ok {
allowed = false
} else if !chelpers.IsSteamIDWhitelisted(steamid.(string)) {
allowed = false
}
} else {
allowed = false
}
if !allowed {
http.Error(w, "Sorry, but you're not in the closed alpha", 403)
return
}
}
session, err := chelpers.GetSessionHTTP(r)
var so *wsevent.Client
if err == nil {
_, ok := session.Values["steam_id"]
if ok {
so, err = server.NewClient(upgrader, w, r)
} else {
so, err = noauth.NewClient(upgrader, w, r)
}
} else {
var estr = "Couldn't create WebSocket connection."
//estr = err.Error()
http.Error(w, estr, 500)
return
}
if err != nil || so == nil {
controllers.LogoutSession(w, r)
return
}
//helpers.Logger.Debug("Connected to Socket")
err = socket.SocketInit(server, noauth, so)
if err != nil {
controllers.LogoutSession(w, r)
}
})
}