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


Golang mux.NewRouter函數代碼示例

本文整理匯總了Golang中code/google/com/p/gorilla/mux.NewRouter函數的典型用法代碼示例。如果您正苦於以下問題:Golang NewRouter函數的具體用法?Golang NewRouter怎麽用?Golang NewRouter使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了NewRouter函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: NewRouter

// Creates new http.Handler that can be used in http.ServeMux (e.g. http.DefaultServeMux)
func NewRouter(baseUrl string, h HandlerFunc, cfg Config) http.Handler {
	router := mux.NewRouter()
	ctx := &context{
		Config:      cfg,
		HandlerFunc: h,
		connections: newConnections(),
	}
	sub := router.PathPrefix(baseUrl).Subrouter()
	sub.HandleFunc("/info", ctx.wrap((*context).infoHandler)).Methods("GET")
	sub.HandleFunc("/info", infoOptionsHandler).Methods("OPTIONS")
	ss := sub.PathPrefix("/{serverid:[^./]+}/{sessionid:[^./]+}").Subrouter()
	ss.HandleFunc("/xhr_streaming", ctx.wrap((*context).XhrStreamingHandler)).Methods("POST")
	ss.HandleFunc("/xhr_send", ctx.wrap((*context).XhrSendHandler)).Methods("POST")
	ss.HandleFunc("/xhr_send", xhrOptions).Methods("OPTIONS")
	ss.HandleFunc("/xhr_streaming", xhrOptions).Methods("OPTIONS")
	ss.HandleFunc("/xhr", ctx.wrap((*context).XhrPollingHandler)).Methods("POST")
	ss.HandleFunc("/xhr", xhrOptions).Methods("OPTIONS")
	ss.HandleFunc("/eventsource", ctx.wrap((*context).EventSourceHandler)).Methods("GET")
	ss.HandleFunc("/jsonp", ctx.wrap((*context).JsonpHandler)).Methods("GET")
	ss.HandleFunc("/jsonp_send", ctx.wrap((*context).JsonpSendHandler)).Methods("POST")
	ss.HandleFunc("/htmlfile", ctx.wrap((*context).HtmlfileHandler)).Methods("GET")
	ss.HandleFunc("/websocket", webSocketPostHandler).Methods("POST")
	ss.HandleFunc("/websocket", ctx.wrap((*context).WebSocketHandler)).Methods("GET")

	sub.HandleFunc("/iframe.html", ctx.wrap((*context).iframeHandler)).Methods("GET")
	sub.HandleFunc("/iframe-.html", ctx.wrap((*context).iframeHandler)).Methods("GET")
	sub.HandleFunc("/iframe-{ver}.html", ctx.wrap((*context).iframeHandler)).Methods("GET")
	sub.HandleFunc("/", welcomeHandler).Methods("GET")
	sub.HandleFunc("/websocket", ctx.wrap((*context).RawWebSocketHandler)).Methods("GET")
	return router
}
開發者ID:prinsmike,項目名稱:sockjs-go,代碼行數:32,代碼來源:router.go

示例2: Main

func (c *runCmd) Main() {
	c.configuredCmd.Main()
	InitLog()
	// Create an HTTP request router
	r := mux.NewRouter()
	// Add common static routes
	NewStaticRouter(r)
	// Create HKP router
	hkpRouter := hkp.NewRouter(r)
	// Create SKS peer
	sksPeer, err := openpgp.NewSksPeer(hkpRouter.Service)
	if err != nil {
		die(err)
	}
	// Launch the OpenPGP workers
	for i := 0; i < openpgp.Config().NumWorkers(); i++ {
		w, err := openpgp.NewWorker(hkpRouter.Service, sksPeer)
		if err != nil {
			die(err)
		}
		// Subscribe SKS to worker's key changes
		w.SubKeyChanges(sksPeer.KeyChanges)
		go w.Run()
	}
	sksPeer.Start()
	// Bind the router to the built-in webserver root
	http.Handle("/", r)
	// Start the built-in webserver, run forever
	err = http.ListenAndServe(hkp.Config().HttpBind(), nil)
	die(err)
}
開發者ID:kisom,項目名稱:hockeypuck,代碼行數:31,代碼來源:run.go

示例3: main

func main() {
	files, err := filepath.Glob("img/*.jpg")
	if err != nil {
		log.Fatal(err)
		return
	}

	if len(files) == 0 {
		log.Fatal("no images found!")
		return
	}

	sort.Strings(files)

	r := mux.NewRouter()
	h := new(handler)
	h.files = files
	h.start_time = time.Now()

	r.Handle("/{g:[g/]*}{width:[1-9][0-9]*}/{height:[1-9][0-9]*}", h)
	r.Handle("/{g:[g/]*}{width:[1-9][0-9]*}x{height:[1-9][0-9]*}", h)
	r.Handle("/{g:[g/]*}{size:[1-9][0-9]*}", h)
	r.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
		http.ServeFile(w, r, "public/index.html")
	})

	http.ListenAndServe(":"+os.Getenv("PORT"), r)
}
開發者ID:georgebashi,項目名稱:pugholder,代碼行數:28,代碼來源:main.go

示例4: New

func New(db *database.Database, directory string) *Environment {
	return &Environment{
		Db:       db,
		Router:   mux.NewRouter(),
		TmplPath: directory,
	}
}
開發者ID:yeison,項目名稱:musicrawler,代碼行數:7,代碼來源:env.go

示例5: main

func main() {
	r := mux.NewRouter()
	http.Handle("/assets/", http.StripPrefix("/assets", http.FileServer(http.Dir("./assets"))))
	r.HandleFunc("/", indexHandler)
	r.HandleFunc(notePath+"{note}", noteHandler)
	http.Handle("/", r)
	http.ListenAndServe(":8080", nil)
}
開發者ID:Zensavona,項目名稱:Blog,代碼行數:8,代碼來源:blog.go

示例6: main

func main() {
	r := mux.NewRouter()
	r.HandleFunc("/", index)
	r.HandleFunc("/mustache", mustache)
	r.HandleFunc("/tmpl", tmpl)
	http.Handle("/", r)
	http.ListenAndServe(":3000", nil)
}
開發者ID:freewind,項目名稱:GolangBlogDemo,代碼行數:8,代碼來源:server.go

示例7: main

func main() {
	r := mux.NewRouter()
	r.HandleFunc("/", handler)
	e := http.ListenAndServe(":"+os.Getenv("PORT"), r)
	if e != nil {
		panic(e)
	}
}
開發者ID:surma-dump,項目名稱:heroku-buildpack-go-app,代碼行數:8,代碼來源:app.go

示例8: createmux

func createmux() *mux.Router {
	r := mux.NewRouter()
	r.HandleFunc("/gull", ListHandler).Methods("GET")
	r.HandleFunc("/gull/{id}", ViewHandler).Methods("GET")
	r.HandleFunc("/gull/{id}", DeleteHandler).Methods("DELETE")
	r.HandleFunc("/gull", AddHandler).Methods("POST")
	return r
}
開發者ID:errnoh,項目名稱:wepa2012,代碼行數:8,代碼來源:controllers.go

示例9: init

func init() {
	r := mux.NewRouter()
	r.HandleFunc("/", HomeHandler)
	r.HandleFunc("/api/kanji/{literal}", KanjiDetailHandler)
	r.HandleFunc("/api/search/{reading}/{term}", KanjiSearchHandler)
	r.HandleFunc("/{path:.*}", HomeHandler)
	http.Handle("/", r)
}
開發者ID:shawnps,項目名稱:kanjihub,代碼行數:8,代碼來源:kanjihub.go

示例10: routerSetup

func routerSetup() {
	router = mux.NewRouter()
	router.HandleFunc("/", indexHandler)
	router.HandleFunc("/tweet/{id}", showHandler)
	router.HandleFunc("/search", indexHandler)

	http.Handle("/", router)
	http.Handle("/public/", http.FileServer(http.Dir(rootPath)))
}
開發者ID:nexneo,項目名稱:topturls,代碼行數:9,代碼來源:router.go

示例11: createMux

func createMux() (r *mux.Router) {
	r = mux.NewRouter()

	r.HandleFunc("/app/observation", ListObservationHandler).Methods("GET")
	r.HandleFunc("/app/observation", AddObservationHandler).Methods("POST")
	r.HandleFunc("/app/observationpoint", ListPointHandler).Methods("GET")
	r.HandleFunc("/app/observationpoint", AddPointHandler).Methods("POST")
	return r
}
開發者ID:errnoh,項目名稱:wepa2012,代碼行數:9,代碼來源:controllers.go

示例12: main

func main() {
	r := mux.NewRouter()
	r.HandleFunc("/{key}", PageHandler)
	r.HandleFunc("/{key}/{asset}", AssetHandler)
	r.HandleFunc("/static/", http.FileServer(http.Dir(filepath.Join(root, "static"))))
	if err := http.ListenAndServe(":8080", r); err != nil {
		log.Fatal("ListenAndServe:", err)
	}
}
開發者ID:davecheney,項目名稱:zuul,代碼行數:9,代碼來源:main.go

示例13: serveBlockpage

func serveBlockpage() {
	r := mux.NewRouter()
	r.PathPrefix("/iframe/").Handler(http.StripPrefix("/iframe", http.FileServer(http.Dir("./blockpage"))))
	r.PathPrefix("/").HandlerFunc(iframeHandler)
	e := http.ListenAndServe(":80", r)
	if e != nil {
		log.Fatalf("serveBlockpage: Could not bind http server: %s", e)
	}
}
開發者ID:surma,項目名稱:diplomaenhancer,代碼行數:9,代碼來源:blockpage.go

示例14: endpoint

//JSON endpoints:
//	/{ID}		specific post
//	/blog		list of all posts
func endpoint() {
	router := mux.NewRouter()
	r := router.Host("{domain:pleskac.org|www.pleskac.org|localhost}").Subrouter()
	r.HandleFunc("/blog", HomeHandler)
	r.HandleFunc("/blog/{"+postId+":[0-9]+}", PostHandler)
	r.HandleFunc("/{"+postId+":[0-9]+}", PostDataHandler)

	http.ListenAndServe(":1337", r)
}
開發者ID:pleskac,項目名稱:blog,代碼行數:12,代碼來源:server.go

示例15: Router

func Router() *mux.Router {

	router := mux.NewRouter()

	router.HandleFunc("/", handlers.RenderHtml("main.html"))
	router.HandleFunc("/js/{script:.*}", handlers.RenderJavascripts)

	return router
}
開發者ID:sjltaylor,項目名稱:datagram.io,代碼行數:9,代碼來源:router.go


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