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

Golang traffic.New函数代码示例

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

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



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

示例1: init

func init() {
	router = traffic.New()

	router.Get("/", RootHandler)

	// match (width)x(height) format
	// we cannot choose which character set the named routes can take
	// they only stop matching on / # ? ( ) . \
	// we should be able to do something like
	// (:width=[\d+])(x(:height=[\d+]))?
	// or something even simplier like
	// (:width=:digits)(x(:height=:digits))(.(:format=json|xml|atom))
	router.Get(`/(?P<width>\d+)(x(?P<height>\d+)?)?/?`, ImageHandler).
		AddBeforeFilter(RequireValidImageParameters).
		AddBeforeFilter(GenerateImageCache)

	router.Get(`/:width/?(:height)?/?`, ImageHandler).
		AddBeforeFilter(RequireValidImageParameters).
		AddBeforeFilter(GenerateImageCache)

	// Executed before all handlers
	router.AddBeforeFilter(PoweredByHandler)

	// Custom not found handler
	router.NotFoundHandler = NotFoundHandler

	// if not in development, add the static handler
	if traffic.Env() == "production" {
		router.Use(traffic.NewStaticMiddleware(traffic.PublicPath()))
	}

}
开发者ID:jmptrader,项目名称:purrraceholder,代码行数:32,代码来源:main.go


示例2: main

func main() {
	router := traffic.New()
	router.Get("/", rootHandler)
	router.Get("/server_side/", serverSideHandler).AddBeforeFilter(addLocationHeader)
	router.Get("/facetime/", facetimeHandler)
	router.Get("/third_party/", thirdPartyHandler)
	router.NotFoundHandler = customNotFoundHandler
	router.Run()
}
开发者ID:karmatr0n,项目名称:url-schemes,代码行数:9,代码来源:main.go


示例3: init

func init() {
	initDatabase()

	router = traffic.New()
	router.NotFoundHandler = NotFoundHandler
	router.ErrorHandler = ErrorHandler
	router.AddBeforeFilter(SetDefaultHeaders)

	router.Get("/", RootHandler)
	// Artist:
	//   /artists/056e4f3e-d505-4dad-8ec1-d04f521cbb56
	router.Get("/artists/:id.json", ArtistHandler)

	// Release Group:
	//   /release-groups/aa997ea0-2936-40bd-884d-3af8a0e064dc
	//   /artists/056e4f3e-d505-4dad-8ec1-d04f521cbb56/release-groups/aa997ea0-2936-40bd-884d-3af8a0e064dc
	router.Get("(/artists/:artist_id)?/release-groups/:id.json", ReleaseGroupHandler).
		AddBeforeFilter(CheckArtistFilter)

	// Release Groups:
	//   /artists/056e4f3e-d505-4dad-8ec1-d04f521cbb56/release-groups
	router.Get("/artists/:artist_id/release-groups.json", ReleaseGroupsHandler).
		AddBeforeFilter(CheckArtistFilter)

	// Release:
	//   /releases/79215cdf-4764-4dee-b0b9-fec1643df7c5
	//   /artists/056e4f3e-d505-4dad-8ec1-d04f521cbb56/releases/79215cdf-4764-4dee-b0b9-fec1643df7c5
	router.Get("(/artists/:artist_id)?/releases/:id.json", ReleaseHandler).
		AddBeforeFilter(CheckArtistFilter)

	// Releases:
	//   /artists/056e4f3e-d505-4dad-8ec1-d04f521cbb56/releases
	router.Get("/artists/:artist_id/releases.json", ReleasesHandler).
		AddBeforeFilter(CheckArtistFilter)

	// Releases:
	//   /release-groups/aa997ea0-2936-40bd-884d-3af8a0e064dc/releases
	//   /artists/056e4f3e-d505-4dad-8ec1-d04f521cbb56/release-groups/aa997ea0-2936-40bd-884d-3af8a0e064dc/releases
	router.Get("(/artists/:artist_id)?/release-groups/:release_group_id/releases.json", ReleasesHandler).
		AddBeforeFilter(CheckArtistFilter).
		AddBeforeFilter(CheckReleaseGroupFilter)

	// Recordings:
	//   /releases/79215cdf-4764-4dee-b0b9-fec1643df7c5/recordings
	//   /artists/056e4f3e-d505-4dad-8ec1-d04f521cbb56/releases/79215cdf-4764-4dee-b0b9-fec1643df7c5/recordings
	router.Get("(/artists/:artist_id)?/releases/:release_id/recordings.json", RecordingsHandler).
		AddBeforeFilter(CheckArtistFilter).
		AddBeforeFilter(CheckReleaseFilter)

	// Recording:
	//   /recordings/0c871a4a-efdf-47f8-98c2-cc277f806d2f
	//   /releases/79215cdf-4764-4dee-b0b9-fec1643df7c5/recordings/0c871a4a-efdf-47f8-98c2-cc277f806d2f
	//   /artists/056e4f3e-d505-4dad-8ec1-d04f521cbb56/releases/79215cdf-4764-4dee-b0b9-fec1643df7c5/recordings/833f00e1-781f-4edd-90e4-e52712618862
	router.Get("((/artists/:artist_id)?/releases/:release_id)?/recordings/:id.json", RecordingHandler).
		AddBeforeFilter(CheckArtistFilter).
		AddBeforeFilter(CheckReleaseFilter)
}
开发者ID:pilu,项目名称:cerebellum,代码行数:57,代码来源:cerebellum.go


示例4: main

func main() {
	traffic.TemplateFunc("upcase", strings.ToUpper)
	traffic.TemplateFunc("downcase", strings.ToLower)

	router := traffic.New()
	router.Get("/", indexHandler)
	router.Get("/about/?", aboutHandler)
	router.Run()
}
开发者ID:jmptrader,项目名称:traffic,代码行数:9,代码来源:main.go


示例5: main

func main() {
	traffic.SetVar("env", "production")
	router := traffic.New()
	router.Use(airbrake.New(os.Getenv("AIRBRAKE_API_KEY")))

	// Routes
	router.Get("/", rootHandler)
	router.Run()
}
开发者ID:pilu,项目名称:traffic-airbrake,代码行数:9,代码来源:main.go


示例6: BenchmarkPiluTraffic_Simple

func BenchmarkPiluTraffic_Simple(b *testing.B) {
	traffic.SetVar("env", "production")
	router := traffic.New()
	router.Get("/action", piluTrafficHandler)
	rw, r := testRequest("GET", "/action")
	b.ResetTimer()
	for i := 0; i < b.N; i++ {
		router.ServeHTTP(rw, r)
	}
}
开发者ID:rexk,项目名称:golang-mux-benchmark,代码行数:10,代码来源:mux_bench_test.go


示例7: Start

func (api *ImgServerApi) Start() {

	traffic.SetHost(api.host)
	traffic.SetPort(api.port)
	router := traffic.New()
	router.Get("/", api.listHandler)
	router.Put("/", api.statsHandler)
	router.Get("/:image", api.imageHandler)
	router.Post("/:image", api.uploadHandler)
	router.Put("/:src/:dst", api.copyHandler)
	router.Delete("/:image", api.deleteHandler)
	router.Run()
}
开发者ID:jhyle,项目名称:imgserver,代码行数:13,代码来源:api.go


示例8: piluTrafficRouterFor

func piluTrafficRouterFor(namespaces []string, resources []string) http.Handler {
	traffic.SetVar("env", "production")
	router := traffic.New()
	for _, ns := range namespaces {
		for _, res := range resources {
			router.Get("/"+ns+"/"+res, piluTrafficHandler)
			router.Post("/"+ns+"/"+res, piluTrafficHandler)
			router.Get("/"+ns+"/"+res+"/:id", piluTrafficHandler)
			router.Put("/"+ns+"/"+res+"/:id", piluTrafficHandler)
			router.Delete("/"+ns+"/"+res+"/:id", piluTrafficHandler)
		}
	}
	return router
}
开发者ID:rexk,项目名称:golang-mux-benchmark,代码行数:14,代码来源:mux_bench_test.go


示例9: init

func init() {
	var err error
	dbString := os.Getenv("DB")
	DB, err = sql.Open("postgres", dbString)
	if err != nil {
		log.Fatal(err)
	}
	lyricfindClient = lyricfind.NewClient()

	router = traffic.New()
	router.AddBeforeFilter(SetResponseHeaders)
	router.Get("/", RootHandler)
	router.Get("/recordings/:gid", RecordingHandler)
	router.NotFoundHandler = NotFoundHandler
}
开发者ID:pilu,项目名称:microphone,代码行数:15,代码来源:microphone.go


示例10: loadTrafficSingle

func loadTrafficSingle(method, path string, handler traffic.HttpHandleFunc) http.Handler {
	router := traffic.New()
	switch method {
	case "GET":
		router.Get(path, handler)
	case "POST":
		router.Post(path, handler)
	case "PUT":
		router.Put(path, handler)
	case "PATCH":
		router.Patch(path, handler)
	case "DELETE":
		router.Delete(path, handler)
	default:
		panic("Unknow HTTP method: " + method)
	}
	return router
}
开发者ID:lamproae,项目名称:go-http-routing-benchmark,代码行数:18,代码来源:routers.go


示例11: loadTraffic

func loadTraffic(routes []route) http.Handler {
	router := traffic.New()
	for _, route := range routes {
		switch route.method {
		case "GET":
			router.Get(route.path, trafficHandler)
		case "POST":
			router.Post(route.path, trafficHandler)
		case "PUT":
			router.Put(route.path, trafficHandler)
		case "PATCH":
			router.Patch(route.path, trafficHandler)
		case "DELETE":
			router.Delete(route.path, trafficHandler)
		default:
			panic("Unknow HTTP method: " + route.method)
		}
	}
	return router
}
开发者ID:lamproae,项目名称:go-http-routing-benchmark,代码行数:20,代码来源:routers.go


示例12: BenchmarkPiluTraffic_Middleware

func BenchmarkPiluTraffic_Middleware(b *testing.B) {
	traffic.SetVar("env", "production")
	router := traffic.New()
	router.Use(&trafficMiddleware{})
	router.Use(&trafficMiddleware{})
	router.Use(&trafficMiddleware{})
	router.Use(&trafficMiddleware{})
	router.Use(&trafficMiddleware{})
	router.Use(&trafficMiddleware{})
	router.Get("/action", piluTrafficHandler)

	rw, req := testRequest("GET", "/action")

	b.ResetTimer()
	for i := 0; i < b.N; i++ {
		router.ServeHTTP(rw, req)
		if rw.Code != 200 {
			panic("no good")
		}
	}
}
开发者ID:rexk,项目名称:golang-mux-benchmark,代码行数:21,代码来源:mux_bench_test.go


示例13: BenchmarkPiluTraffic_Composite

func BenchmarkPiluTraffic_Composite(b *testing.B) {
	namespaces, resources, requests := resourceSetup(10)

	traffic.SetVar("env", "production")
	router := traffic.New()
	router.Use(&trafficCompositeMiddleware{})
	router.Use(&trafficMiddleware{})
	router.Use(&trafficMiddleware{})
	router.Use(&trafficMiddleware{})
	router.Use(&trafficMiddleware{})
	router.Use(&trafficMiddleware{})

	for _, ns := range namespaces {
		for _, res := range resources {
			router.Get("/"+ns+"/"+res, piluTrafficCompositeHandler)
			router.Post("/"+ns+"/"+res, piluTrafficCompositeHandler)
			router.Get("/"+ns+"/"+res+"/:id", piluTrafficCompositeHandler)
			router.Put("/"+ns+"/"+res+"/:id", piluTrafficCompositeHandler)
			router.Delete("/"+ns+"/"+res+"/:id", piluTrafficCompositeHandler)
		}
	}
	benchmarkRoutes(b, router, requests)
}
开发者ID:rexk,项目名称:golang-mux-benchmark,代码行数:23,代码来源:mux_bench_test.go


示例14: main

func main() {
	router := traffic.New()
	router.Use(chromelogger.New())
	router.Get("/", rootHandler)
	router.Run()
}
开发者ID:pilu,项目名称:traffic-chromelogger,代码行数:6,代码来源:main.go


示例15: startTraffic

func startTraffic() {
	traffic.SetVar("env", "bench")
	mux := traffic.New()
	mux.Get("/hello", trafficHandler)
	http.ListenAndServe(":"+strconv.Itoa(port), mux)
}
开发者ID:cokeboL,项目名称:go-web-framework-benchmark,代码行数:6,代码来源:server.go


示例16: init

func init() {
	router = traffic.New()
	router.Get("/", RootHandler)
}
开发者ID:jmptrader,项目名称:traffic,代码行数:4,代码来源:main.go


示例17: init

func init() {
	app = traffic.New()
	app.Get("/", rootHandler)
	app.Get("/:code", codesHandler)
}
开发者ID:pilu,项目名称:stickerl,代码行数:5,代码来源:stickerl.go



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Golang traffic.Request类代码示例发布时间:2022-05-28
下一篇:
Golang miniassert.Equal函数代码示例发布时间:2022-05-28
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

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

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

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