本文整理匯總了Golang中http.ServeMux類的典型用法代碼示例。如果您正苦於以下問題:Golang ServeMux類的具體用法?Golang ServeMux怎麽用?Golang ServeMux使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
在下文中一共展示了ServeMux類的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: Mux
// 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: registerPublicHandlers
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)
}
示例3: NewFederation
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
}
示例4: Run
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)
}
}
示例5: Attach
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)
}
}))
}
示例6: registerPublicHandlers
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))
}