Пример #1
0
// Mux maps resources to the http.ServeMux mux under the resource given.
// The resource must end with a slash and if the mux is nil, the
// http.DefaultServeMux is used. It registers handlers for URLs like:
// <resource><t.resource>[/], e.g. /socket.io/websocket && socket.io/websocket/.
func (sio *SocketIO) Mux(resource string, mux *http.ServeMux) os.Error {
	if mux == nil {
		mux = http.DefaultServeMux
	}

	if sio.muxed {
		return os.NewError("Mux: already muxed")
	}

	if resource == "" || resource[len(resource)-1] != '/' {
		return os.NewError("Mux: resource must end with a slash")
	}

	for _, t := range sio.config.Transports {
		tt := t
		tresource := resource + tt.Resource()
		mux.HandleFunc(tresource+"/", func(w http.ResponseWriter, req *http.Request) {
			sio.handle(tt, w, req)
		})
		mux.HandleFunc(tresource, func(w http.ResponseWriter, req *http.Request) {
			sio.handle(tt, w, req)
		})
	}

	sio.muxed = true
	return nil
}
Пример #2
0
func NewFederation(userid, domain string, port int, mux *http.ServeMux, ns NameService, store store.BlobStore) *Federation {
	fed := &Federation{userID: userid, ns: ns, store: store, domain: domain, queues: make(map[string]*queue)}
	f := func(w http.ResponseWriter, req *http.Request) {
		fed.handleRequest(w, req)
	}
	pattern := fmt.Sprintf("%v:%v/fed", domain, port)
	mux.HandleFunc(pattern, f)
	return fed
}
Пример #3
0
func registerPublicHandlers(mux *http.ServeMux) {
	mux.Handle(cmdHandler.pattern, &cmdHandler)
	mux.Handle(pkgHandler.pattern, &pkgHandler)
	mux.HandleFunc("/doc/codewalk/", codewalk)
	mux.HandleFunc("/search", search)
	mux.Handle("/robots.txt", fileServer)
	mux.HandleFunc("/", serveFile)
}