當前位置: 首頁>>代碼示例>>Golang>>正文


Golang Server.NewClient方法代碼示例

本文整理匯總了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)
		}
	})
}
開發者ID:demipixel,項目名稱:Helen,代碼行數:60,代碼來源:routes.go


注:本文中的github.com/TF2Stadium/wsevent.Server.NewClient方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。