示例#1
0
文件: main.go 项目: th3oSMith/greader
func Serve() {
	http.Handle("/test", loggingHandler(http.HandlerFunc(testHandler)))
	http.Handle("/panic", loggingHandler(recoverHandler(http.HandlerFunc(panicHandler))))
	http.HandleFunc("/websocket", websocketEchoHandler)

	// Pure Test
	mux := pure.NewPureMux()
	h := pure_test.NewPureHandler()
	mux.RegisterHandler("data", h)

	http.Handle("/pure", pure.WebsocketHandler(*mux))

	yes := singleUserAuthenticator{"tata", "yoyo"}
	http.Handle("/protected", loggingHandler(recoverHandler(yes.authHandler(http.HandlerFunc(testHandler)))))
	http.ListenAndServe(":3000", nil)
}
示例#2
0
func TestPureMux(t *testing.T) {

	mux := pure.NewPureMux()
	h := MyHandler{data: make(map[string]interface{}), owner: make(map[string]pure.PureConnection)}
	mux.RegisterHandler("data", h)

	c1 := pure.GoConn{Response: make(chan pure.PureMsg, 1), Muxer: mux}
	c2 := pure.GoConn{Response: make(chan pure.PureMsg, 1), Muxer: mux}

	mm := make(map[string]interface{})
	mm["id"] = "tata"
	mm["value"] = "yoyo"

	c1.SendReq(pure.PureMsg{DataType: "data", Action: "create", RequestMap: mm})
	resp := c1.ReadResp()

	if resp.Action != "CREATED" {
		t.Error("Create failed", resp)
	}

	c1.SendReq(pure.PureMsg{DataType: "data", Action: "create", RequestMap: mm})
	resp = c1.ReadResp()

	if resp.Action != "CREATE_FAIL" {
		t.Error("Create succeeded", resp)
	}

	c2.SendReq(pure.PureMsg{DataType: "data", Action: "retrieve", RequestMap: mm})
	resp = c2.ReadResp()

	if resp.ResponseMap["data"] != "yoyo" {
		t.Error("Retrieve Fail", resp)
	}

	resp = c1.ReadResp()
	if resp.ResponseMap["data"] != "yoyo" {
		t.Error("Broadcast Fail", resp)
	}

}