• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Golang mux.NewRouter函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Golang中code/google/com/p/gorilla/mux.NewRouter函数的典型用法代码示例。如果您正苦于以下问题:Golang NewRouter函数的具体用法?Golang NewRouter怎么用?Golang NewRouter使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了NewRouter函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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


示例16: main

func main() {
	runtime.GOMAXPROCS(runtime.NumCPU())

	// read configurations
	confKeys := []string{"SHAWTY_PORT", "SHAWTY_DB", "SHAWTY_DOMAIN", "SHAWTY_MODE", "SHAWTY_LPM", "SHAWTY_LOG_DIR"}
	config := make(map[string]string)
	for _, k := range confKeys {
		config[k] = os.Getenv(k)
	}

	// setup logger
	log.SetDir(config["SHAWTY_LOG_DIR"])

	// setup data
	random := utils.NewBestRand()
	shawties, err := data.NewMySh(random, config["SHAWTY_DB"])
	if err != nil {
		log.Error("Cannot create MySh")
		return
	}
	defer shawties.Close()

	// register routes
	home := web.NewHomeController(config)
	shawtyjs := web.NewShawtyJSController(config, shawties)
	shortID := web.NewShortIDController(config, shawties)

	// setup HTTP server
	router := mux.NewRouter()
	router.PathPrefix("/static/").Handler(http.StripPrefix("/static/", http.FileServer(http.Dir("static/"))))
	router.Handle("/", home)
	router.Handle("/shawty.js", shawtyjs)
	router.Handle("/{shortID:[A-Za-z0-9]+}", shortID)

	var port = config["SHAWTY_PORT"]
	if port == "" {
		port = "80"
	}

	l, err := net.Listen("tcp", "0.0.0.0:"+port)
	if err != nil {
		log.Errorf("Cannot listen at %s", port)
		fmt.Println(err)
		return
	}
	defer l.Close()
	log.Infof("Listening at %s", port)

	runMode := config["SHAWTY_MODE"]
	switch runMode {
	case "fcgi":
		fcgi.Serve(l, router)
	default:
		http.Serve(l, router)
	}
}
开发者ID:jnlopar,项目名称:shawty,代码行数:56,代码来源:main.go


示例17: Benchmark_GorillaHandler

// Benchmark_Gorilla runs a benchmark against the Gorilla Mux using
// the default settings.
func Benchmark_GorillaHandler(b *testing.B) {

	handler := gorilla.NewRouter()
	handler.HandleFunc("/person/{last}/{first}", HandlerOk)

	for i := 0; i < b.N; i++ {
		r, _ := http.NewRequest("GET", "/person/anderson/thomas?learn=kungfu", nil)
		w := httptest.NewRecorder()
		handler.ServeHTTP(w, r)
	}
}
开发者ID:rlizana,项目名称:routes,代码行数:13,代码来源:bench_test.go


示例18: InitAndRun

func InitAndRun(corpusPath, port string) {
	m = &indexContainer{}
	m.iIndex = NewInvertedIndex()
	m.fIndex = NewForwardIndex()

	InitIndex(m.iIndex, m.fIndex, corpusPath)

	r := mux.NewRouter()
	r.HandleFunc("/cleo/{query}", Search)
	http.Handle("/", r)
	log.Fatal(http.ListenAndServe(":"+port, nil))
}
开发者ID:jbowles,项目名称:gocleo,代码行数:12,代码来源:cleo.go


示例19: main

func main() {
	r := mux.NewRouter()
	r.HandleFunc("/", HomeHandler)
	r.HandleFunc("/upload", UploadHandler)
	//r.HandleFunc("/{sessionId:[0-9]+}", SessionHandler)
	//r.HandleFunc(`/{sessionId:[0-9]+}/{fileName:.*\.html}`, SessionHandler)
	http.Handle("/static/", http.StripPrefix("/static/", http.FileServer(http.Dir("static/"))))
	http.Handle("/", r)
	err := http.ListenAndServe(":80", nil)
	if err != nil {
		log.Fatal("ListenAndServe: ", err)
	}
}
开发者ID:ZhuBicen,项目名称:FileUploadDemo,代码行数:13,代码来源:server.go


示例20: NewMvcInfrastructure

// NewMvcInfrastructure creates a new MvcInfrastructure object
func NewMvcInfrastructure() *MvcInfrastructure {
	mvcI := new(MvcInfrastructure)

	mvcI.handlers = make(map[Controller]map[Action]map[method]*methodDescriptor, 0)
	mvcI.views = make(map[Controller]map[Action]*templateDescriptor, 0)
	//mvcI.controllers = make([]ControllerInterface, 0)
	mvcI.controllerConstructors = make(map[Controller]reflect.Value, 0)

	mvcI.Router = mux.NewRouter()
	mvcI.Router.NotFoundHandler = NewNotFoundHandler(mvcI)

	return mvcI
}
开发者ID:WiseBird,项目名称:trinity,代码行数:14,代码来源:mvc.go



注:本文中的code/google/com/p/gorilla/mux.NewRouter函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Golang mux.Vars函数代码示例发布时间:2022-05-24
下一篇:
Golang proto.UnmarshalJSONEnum函数代码示例发布时间:2022-05-24
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap