本文整理汇总了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)
}
})
}