{"id":13571279,"url":"https://github.com/gravityblast/traffic","last_synced_at":"2025-04-05T17:07:40.317Z","repository":{"id":9977236,"uuid":"12004328","full_name":"gravityblast/traffic","owner":"gravityblast","description":"Sinatra inspired regexp/pattern mux and web framework for Go [NOT MAINTAINED]","archived":false,"fork":false,"pushed_at":"2019-10-22T06:25:14.000Z","size":149,"stargazers_count":521,"open_issues_count":1,"forks_count":34,"subscribers_count":24,"default_branch":"master","last_synced_at":"2024-05-30T00:18:16.127Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/gravityblast.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2013-08-09T15:39:44.000Z","updated_at":"2024-03-27T23:05:31.000Z","dependencies_parsed_at":"2022-08-30T23:40:31.363Z","dependency_job_id":null,"html_url":"https://github.com/gravityblast/traffic","commit_stats":null,"previous_names":["pilu/traffic"],"tags_count":7,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gravityblast%2Ftraffic","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gravityblast%2Ftraffic/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gravityblast%2Ftraffic/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gravityblast%2Ftraffic/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/gravityblast","download_url":"https://codeload.github.com/gravityblast/traffic/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247369952,"owners_count":20927928,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-08-01T14:01:00.483Z","updated_at":"2025-04-05T17:07:40.278Z","avatar_url":"https://github.com/gravityblast.png","language":"Go","readme":"# Traffic\n\n[![Build Status](https://travis-ci.org/pilu/traffic.png?branch=master)](https://travis-ci.org/pilu/traffic)\n\nPackage traffic - a Sinatra inspired regexp/pattern mux for [Go](http://golang.org/ \"The Go programming language\").\n\n## Installation\n\n    go get github.com/pilu/traffic\n\n## Features\n\n  * [Regexp routing](https://github.com/pilu/traffic/blob/master/examples/simple/main.go)\n  * [Before Filters](https://github.com/pilu/traffic/blob/master/examples/before-filter/main.go)\n  * [Custom not found handler](https://github.com/pilu/traffic/blob/master/examples/not-found/main.go)\n  * [Middlewares](https://github.com/pilu/traffic/blob/master/examples/middleware/main.go)\n    * Examples: [Airbrake Middleware](https://github.com/pilu/traffic-airbrake), [Chrome Logger Middleware](https://github.com/pilu/traffic-chromelogger)\n  * [Templates/Views](https://github.com/pilu/traffic/tree/master/examples/templates)\n  * [Easy Configuration](https://github.com/pilu/traffic/tree/master/examples/configuration)\n\n## Development Features\n\n  * [Shows errors and stacktrace in browser](https://github.com/pilu/traffic/tree/master/examples/show-errors)\n  * [Serves static files](https://github.com/pilu/traffic/tree/master/examples/static-files)\n  * Project Generator\n\n`development` is the default environment. The above middlewares are loaded only in `development`.\n\nIf you want to run your application in `production`, export `TRAFFIC_ENV` with `production` as value.\n\n```bash\nTRAFFIC_ENV=production your-executable-name\n```\n\n## Installation\n\nDowload the `Traffic` code:\n\n```bash\ngo get github.com/pilu/traffic\n```\n\nBuild the command line tool:\n\n```bash\ngo get github.com/pilu/traffic/traffic\n```\n\nCreate a new project:\n```bash\ntraffic new hello\n```\n\nRun your project:\n```bash\ncd hello\ngo build \u0026\u0026 ./hello\n```\n\nYou can use [Fresh](https://github.com/pilu/fresh) if you want to build and restart your application every time you create/modify/delete a file.\n\n## Example:\nThe following code is a simple example, the documentation in still in development.\nFor more examples check the `examples` folder.\n\n```go\npackage main\n\nimport (\n  \"net/http\"\n  \"github.com/pilu/traffic\"\n  \"fmt\"\n)\n\nfunc rootHandler(w traffic.ResponseWriter, r *traffic.Request) {\n  fmt.Fprint(w, \"Hello World\\n\")\n}\n\nfunc pageHandler(w traffic.ResponseWriter, r *traffic.Request) {\n  params := r.URL.Query()\n  fmt.Fprintf(w, \"Category ID: %s\\n\", params.Get(\"category_id\"))\n  fmt.Fprintf(w, \"Page ID: %s\\n\", params.Get(\"id\"))\n}\n\nfunc main() {\n  router := traffic.New()\n\n  // Routes\n  router.Get(\"/\", rootHandler)\n  router.Get(\"/categories/:category_id/pages/:id\", pageHandler)\n\n  router.Run()\n}\n```\n\n## Before Filters\n\nYou can also add \"before filters\" to all your routes or just to some of them:\n\n```go\nrouter := traffic.New()\n\n// Executed before all handlers\nrouter.AddBeforeFilter(checkApiKey).\n       AddBeforeFilter(addAppNameHeader).\n       AddBeforeFilter(addTimeHeader)\n\n// Routes\nrouter.Get(\"/\", rootHandler)\nrouter.Get(\"/categories/:category_id/pages/:id\", pageHandler)\n\n// \"/private\" has one more before filter that checks for a second api key (private_api_key)\nrouter.Get(\"/private\", privatePageHandler).\n        AddBeforeFilter(checkPrivatePageApiKey)\n```\n\nComplete example:\n\n```go\nfunc rootHandler(w traffic.ResponseWriter, r *traffic.Request) {\n  fmt.Fprint(w, \"Hello World\\n\")\n}\n\nfunc privatePageHandler(w traffic.ResponseWriter, r *traffic.Request) {\n  fmt.Fprint(w, \"Hello Private Page\\n\")\n}\n\nfunc pageHandler(w traffic.ResponseWriter, r *traffic.Request) {\n  params := r.URL.Query()\n  fmt.Fprintf(w, \"Category ID: %s\\n\", params.Get(\"category_id\"))\n  fmt.Fprintf(w, \"Page ID: %s\\n\", params.Get(\"id\"))\n}\n\nfunc checkApiKey(w traffic.ResponseWriter, r *traffic.Request) {\n  params := r.URL.Query()\n  if params.Get(\"api_key\") != \"foo\" {\n    w.WriteHeader(http.StatusUnauthorized)\n  }\n}\n\nfunc checkPrivatePageApiKey(w traffic.ResponseWriter, r *traffic.Request) {\n  params := r.URL.Query()\n  if params.Get(\"private_api_key\") != \"bar\" {\n    w.WriteHeader(http.StatusUnauthorized)\n  }\n}\n\nfunc addAppNameHeader(w traffic.ResponseWriter, r *traffic.Request) {\n  w.Header().Add(\"X-APP-NAME\", \"My App\")\n}\n\nfunc addTimeHeader(w traffic.ResponseWriter, r *traffic.Request) {\n  t := fmt.Sprintf(\"%s\", time.Now())\n  w.Header().Add(\"X-APP-TIME\", t)\n}\n\nfunc main() {\n  router := traffic.New()\n\n  // Routes\n  router.Get(\"/\", rootHandler)\n  router.Get(\"/categories/:category_id/pages/:id\", pageHandler)\n  // \"/private\" has one more before filter that checks for a second api key (private_api_key)\n  router.Get(\"/private\", privatePageHandler).\n          AddBeforeFilter(checkPrivatePageApiKey)\n\n  // Executed before all handlers\n  router.AddBeforeFilter(checkApiKey).\n         AddBeforeFilter(addAppNameHeader).\n         AddBeforeFilter(addTimeHeader)\n\n  router.Run()\n}\n```\n\n## Author\n\n* [Andrea Franz](http://gravityblast.com)\n\n## More\n\n* Code: \u003chttps://github.com/pilu/traffic/\u003e\n* Mailing List: \u003chttps://groups.google.com/d/forum/go-traffic\u003e\n* Chat: \u003chttps://gitter.im/pilu/traffic\u003e\n","funding_links":[],"categories":["Go"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgravityblast%2Ftraffic","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgravityblast%2Ftraffic","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgravityblast%2Ftraffic/lists"}