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


Golang http.ServeMux類代碼示例

本文整理匯總了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
}
開發者ID:andradeandrey,項目名稱:go-socket.io,代碼行數:31,代碼來源:socketio.go

示例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)
}
開發者ID:WXB506,項目名稱:golang,代碼行數:8,代碼來源:godoc.go

示例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
}
開發者ID:AaronO,項目名稱:lightwave,代碼行數:9,代碼來源:federation.go

示例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)
	}
}
開發者ID:hodzanassredin,項目名稱:web.go-donotuse,代碼行數:10,代碼來源:web.go

示例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)
		}
	}))
}
開發者ID:ypb,項目名稱:bwl,代碼行數:12,代碼來源:apage.go

示例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))
}
開發者ID:rapgamer,項目名稱:golang-china,代碼行數:6,代碼來源:godoc.go


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