// 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
}
Exemple #2
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)
}
Exemple #3
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
}
func (s *Server) Run(addr string, mux *http.ServeMux) {
	s.initServer()

	mux.Handle("/", s)
	s.Logger.Printf("web.go serving %s\n", addr)
	err := http.ListenAndServe(addr, mux)
	if err != nil {
		log.Exit("ListenAndServe:", err)
	}
}
Exemple #5
0
Fichier : apage.go Projet : ypb/bwl
func (self *AnonymousPageServer) Attach(s *http.ServeMux) {
	s.Handle(self.prefix, http.HandlerFunc(func(c *http.Conn, r *http.Request) {
		_, name := path.Split(r.URL.Path)
		id, err := strconv.Atoi64(name)
		if err != nil {
			c.WriteHeader(http.StatusBadRequest)
			io.WriteString(c, "invalid page id")
		} else {
			self.getPage(id).ServeHTTP(c, r)
		}
	}))
}
Exemple #6
0
func registerPublicHandlers(mux *http.ServeMux) {
	mux.Handle(cmdHandler.pattern, &cmdHandler)
	mux.Handle(pkgHandler.pattern, &pkgHandler)
	mux.Handle("/search", http.HandlerFunc(search))
	mux.Handle("/", http.HandlerFunc(serveFile))
}