{"id":13511699,"url":"https://github.com/teambition/gear","last_synced_at":"2025-07-01T23:08:25.376Z","repository":{"id":57481158,"uuid":"71258032","full_name":"teambition/gear","owner":"teambition","description":"A lightweight, composable and high performance web service framework for Go.","archived":false,"fork":false,"pushed_at":"2025-04-16T21:50:10.000Z","size":976,"stargazers_count":546,"open_issues_count":1,"forks_count":53,"subscribers_count":36,"default_branch":"master","last_synced_at":"2025-06-27T00:52:15.968Z","etag":null,"topics":["framework","gear","go","hooks","http2","logging","middleware","router","server-push","web"],"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/teambition.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2016-10-18T14:40:37.000Z","updated_at":"2025-06-19T07:58:50.000Z","dependencies_parsed_at":"2023-10-12T06:52:39.787Z","dependency_job_id":"582889a1-edca-4276-8917-8b882579dc65","html_url":"https://github.com/teambition/gear","commit_stats":null,"previous_names":[],"tags_count":160,"template":false,"template_full_name":null,"purl":"pkg:github/teambition/gear","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/teambition%2Fgear","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/teambition%2Fgear/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/teambition%2Fgear/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/teambition%2Fgear/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/teambition","download_url":"https://codeload.github.com/teambition/gear/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/teambition%2Fgear/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":263047676,"owners_count":23405280,"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":["framework","gear","go","hooks","http2","logging","middleware","router","server-push","web"],"created_at":"2024-08-01T03:01:07.253Z","updated_at":"2025-07-01T23:08:25.326Z","avatar_url":"https://github.com/teambition.png","language":"Go","readme":"![Gear](https://raw.githubusercontent.com/teambition/gear/master/gear.png)\n\n[![CI](https://github.com/teambition/gear/actions/workflows/ci-cover.yml/badge.svg)](https://github.com/teambition/gear/actions/workflows/ci-cover.yml)\n[![Codecov](https://codecov.io/gh/teambition/gear/branch/master/graph/badge.svg)](https://codecov.io/gh/teambition/gear)\n[![CodeQL](https://github.com/teambition/gear/actions/workflows/codeql.yml/badge.svg)](https://github.com/teambition/gear/actions/workflows/codeql.yml)\n[![Go Reference](https://pkg.go.dev/badge/github.com/teambition/gear.svg)](https://pkg.go.dev/github.com/teambition/gear)\n[![License](http://img.shields.io/badge/license-mit-blue.svg?style=flat-square)](https://raw.githubusercontent.com/teambition/gear/master/LICENSE)\n\nA lightweight, composable and high performance web service framework for Go.\n\n## Features\n\n- Effective and flexible middlewares flow control, create anything by middleware\n- Powerful and smart HTTP error handling\n- Trie base gear.Router, as faster as [HttpRouter](https://github.com/julienschmidt/httprouter), support regexp parameters and group routes\n- Integrated timeout context.Context\n- Integrated response content compress\n- Integrated structured logging middleware\n- Integrated request body parser\n- Integrated signed cookies\n- Integrated JSON, JSONP, XML and HTML renderer\n- Integrated CORS, Secure, Favicon and Static middlewares\n- More useful methods on gear.Context to manipulate HTTP Request/Response\n- Run HTTP and gRPC on the same port\n- Completely HTTP/2.0 supported\n\n## Documentation\n\n[Go-Documentation](https://godoc.org/github.com/teambition/gear)\n\n## Import\n\n```go\n// package gear\nimport \"github.com/teambition/gear\"\n```\n\n## Design\n\n1. [Server 底层基于原生 net/http 而不是 fasthttp](https://github.com/teambition/gear/blob/master/doc/design.md#1-server-底层基于原生-nethttp-而不是-fasthttp)\n1. [通过 gear.Middleware 中间件模式扩展功能模块](https://github.com/teambition/gear/blob/master/doc/design.md#2-通过-gearmiddleware-中间件模式扩展功能模块)\n1. [中间件的单向顺序流程控制和级联流程控制](https://github.com/teambition/gear/blob/master/doc/design.md#3-中间件的单向顺序流程控制和级联流程控制)\n1. [功能强大，完美集成 context.Context 的 gear.Context](https://github.com/teambition/gear/blob/master/doc/design.md#4-功能强大完美集成-contextcontext-的-gearcontext)\n1. [集中、智能、可自定义的错误和异常处理](https://github.com/teambition/gear/blob/master/doc/design.md#5-集中智能可自定义的错误和异常处理)\n1. [After Hook 和 End Hook 的后置处理](https://github.com/teambition/gear/blob/master/doc/design.md#6-after-hook-和-end-hook-的后置处理)\n1. [Any interface 无限的 gear.Context 状态扩展能力](https://github.com/teambition/gear/blob/master/doc/design.md#7-any-interface-无限的-gearcontext-状态扩展能力)\n1. [请求数据的解析和验证](https://github.com/teambition/gear/blob/master/doc/design.md#8-请求数据的解析和验证)\n\n## FAQ\n\n1. [如何从源码自动生成 Swagger v2 的文档？](https://github.com/teambition/gear/blob/master/doc/faq.md#1-如何从源码自动生成-swagger-v2-的文档)\n1. [Go 语言完整的应用项目结构最佳实践是怎样的？](https://github.com/teambition/gear/blob/master/doc/faq.md#2-go-语言完整的应用项目结构最佳实践是怎样的)\n\n## Demo\n\n### Hello\n\nhttps://github.com/teambition/gear/tree/master/example/hello\n\n```go\n  app := gear.New()\n\n  // Add logging middleware\n  app.UseHandler(logging.Default(true))\n\n  // Add router middleware\n  router := gear.NewRouter()\n\n  // try: http://127.0.0.1:3000/hello\n  router.Get(\"/hello\", func(ctx *gear.Context) error {\n    return ctx.HTML(200, \"\u003ch1\u003eHello, Gear!\u003c/h1\u003e\")\n  })\n\n  // try: http://127.0.0.1:3000/test?query=hello\n  router.Otherwise(func(ctx *gear.Context) error {\n    return ctx.JSON(200, map[string]any{\n      \"Host\":    ctx.Host,\n      \"Method\":  ctx.Method,\n      \"Path\":    ctx.Path,\n      \"URI\":     ctx.Req.RequestURI,\n      \"Headers\": ctx.Req.Header,\n    })\n  })\n  app.UseHandler(router)\n  app.Error(app.Listen(\":3000\"))\n```\n\n### HTTP2 with Push\n\nhttps://github.com/teambition/gear/tree/master/example/http2\n\n```go\npackage main\n\nimport (\n  \"net/http\"\n\n  \"github.com/teambition/gear\"\n  \"github.com/teambition/gear/logging\"\n  \"github.com/teambition/gear/middleware/favicon\"\n)\n\n// go run example/http2/app.go\n// Visit: https://127.0.0.1:3000/\nfunc main() {\n  const htmlBody = `\n\u003c!DOCTYPE html\u003e\n\u003chtml\u003e\n  \u003chead\u003e\n    \u003clink href=\"/hello.css\" rel=\"stylesheet\" type=\"text/css\"\u003e\n  \u003c/head\u003e\n  \u003cbody\u003e\n    \u003ch1\u003eHello, Gear!\u003c/h1\u003e\n  \u003c/body\u003e\n\u003c/html\u003e`\n\n  const pushBody = `\nh1 {\n  color: red;\n}\n`\n\n  app := gear.New()\n\n  app.UseHandler(logging.Default(true))\n  app.Use(favicon.New(\"./testdata/favicon.ico\"))\n\n  router := gear.NewRouter()\n  router.Get(\"/\", func(ctx *gear.Context) error {\n    ctx.Res.Push(\"/hello.css\", \u0026http.PushOptions{Method: \"GET\"})\n    return ctx.HTML(200, htmlBody)\n  })\n  router.Get(\"/hello.css\", func(ctx *gear.Context) error {\n    ctx.Type(\"text/css\")\n    return ctx.End(200, []byte(pushBody))\n  })\n  app.UseHandler(router)\n  app.Error(app.ListenTLS(\":3000\", \"./testdata/out/test.crt\", \"./testdata/out/test.key\"))\n}\n```\n\n### A CMD tool: static server\n\nhttps://github.com/teambition/gear/tree/master/example/staticgo\n\nInstall it with go:\n\n```sh\ngo install github.com/teambition/gear/example/staticgo@latest\n```\n\nIt is a useful CMD tool that serve your local files as web server (support TLS).\nYou can build `osx`, `linux`, `windows` version with `make build`.\n\n```go\npackage main\n\nimport (\n  \"flag\"\n\n  \"github.com/teambition/gear\"\n  \"github.com/teambition/gear/logging\"\n  \"github.com/teambition/gear/middleware/cors\"\n  \"github.com/teambition/gear/middleware/static\"\n)\n\nvar (\n  address  = flag.String(\"addr\", \"127.0.0.1:3000\", `address to listen on.`)\n  path     = flag.String(\"path\", \"./\", `static files path to serve.`)\n  certFile = flag.String(\"certFile\", \"\", `certFile path, used to create TLS static server.`)\n  keyFile  = flag.String(\"keyFile\", \"\", `keyFile path, used to create TLS static server.`)\n)\n\nfunc main() {\n  flag.Parse()\n  app := gear.New()\n\n  app.UseHandler(logging.Default(true))\n  app.Use(cors.New())\n  app.Use(static.New(static.Options{Root: *path}))\n\n  logging.Println(\"staticgo v1.2.0, created by https://github.com/teambition/gear\")\n  logging.Printf(\"listen: %s, serve: %s\\n\", *address, *path)\n\n  if *certFile != \"\" \u0026\u0026 *keyFile != \"\" {\n    app.Error(app.ListenTLS(*address, *certFile, *keyFile))\n  } else {\n    app.Error(app.Listen(*address))\n  }\n}\n```\n\n### A CMD tool: reverse proxy server\n\nhttps://github.com/teambition/gear/tree/master/example/gearproxy\n\nInstall it with go:\n\n```sh\ngo install github.com/teambition/gear/example/gearproxy@latest\ngearproxy -help\n```\n\n### HTTP2 \u0026 gRPC\n\nhttps://github.com/teambition/gear/tree/master/example/grpc_server\n\nhttps://github.com/teambition/gear/tree/master/example/grpc_client\n\n## About Router\n\n[gear.Router](https://godoc.org/github.com/teambition/gear#Router) is a trie base HTTP request handler.\nFeatures:\n\n1. Support named parameter\n1. Support regexp\n1. Support suffix matching\n1. Support multi-router\n1. Support router layer middlewares\n1. Support fixed path automatic redirection\n1. Support trailing slash automatic redirection\n1. Automatic handle `405 Method Not Allowed`\n1. Automatic handle `OPTIONS` method\n1. Best Performance\n\nThe registered path, against which the router matches incoming requests, can contain six types of parameters:\n\n| Syntax                 | Description                                     |\n| ---------------------- | ----------------------------------------------- |\n| `:name`                | named parameter                                 |\n| `:name(regexp)`        | named with regexp parameter                     |\n| `:name+suffix`         | named parameter with suffix matching            |\n| `:name(regexp)+suffix` | named with regexp parameter and suffix matching |\n| `:name*`               | named with catch-all parameter                  |\n| `::name`               | not named parameter, it is literal `:name`      |\n\nNamed parameters are dynamic path segments. They match anything until the next '/' or the path end:\n\nDefined: `/api/:type/:ID`\n\n```md\n/api/user/123             matched: type=\"user\", ID=\"123\"\n/api/user                 no match\n/api/user/123/comments    no match\n```\n\nNamed with regexp parameters match anything using regexp until the next '/' or the path end:\n\nDefined: `/api/:type/:ID(^\\d+$)`\n\n```md\n/api/user/123             matched: type=\"user\", ID=\"123\"\n/api/user                 no match\n/api/user/abc             no match\n/api/user/123/comments    no match\n```\n\nNamed parameters with suffix, such as [Google API Design](https://cloud.google.com/apis/design/custom_methods):\n\nDefined: `/api/:resource/:ID+:undelete`\n\n```md\n/api/file/123                     no match\n/api/file/123:undelete            matched: resource=\"file\", ID=\"123\"\n/api/file/123:undelete/comments   no match\n```\n\nNamed with regexp parameters and suffix:\n\nDefined: `/api/:resource/:ID(^\\d+$)+:cancel`\n\n```md\n/api/task/123                   no match\n/api/task/123:cancel            matched: resource=\"task\", ID=\"123\"\n/api/task/abc:cancel            no match\n```\n\nNamed with catch-all parameters match anything until the path end, including the directory index (the '/' before the catch-all). Since they match anything until the end, catch-all parameters must always be the final path element.\n\nDefined: `/files/:filepath*`\n\n```\n/files                           no match\n/files/LICENSE                   matched: filepath=\"LICENSE\"\n/files/templates/article.html    matched: filepath=\"templates/article.html\"\n```\n\nThe value of parameters is saved on the `Matched.Params`. Retrieve the value of a parameter by name:\n\n```go\ntype := matched.Params(\"type\")\nid   := matched.Params(\"ID\")\n```\n\n## More Middlewares\n\n- Structured logging: [github.com/teambition/gear/logging](https://github.com/teambition/gear/tree/master/logging)\n- CORS handler: [github.com/teambition/gear/middleware/cors](https://github.com/teambition/gear/tree/master/middleware/cors)\n- Secure handler: [github.com/teambition/gear/middleware/secure](https://github.com/teambition/gear/tree/master/middleware/secure)\n- Static serving: [github.com/teambition/gear/middleware/static](https://github.com/teambition/gear/tree/master/middleware/static)\n- Favicon serving: [github.com/teambition/gear/middleware/favicon](https://github.com/teambition/gear/tree/master/middleware/favicon)\n- gRPC serving: [github.com/teambition/gear/middleware/grpc](https://github.com/teambition/gear/tree/master/middleware/grpc)\n- JWT and Crypto auth: [Gear-Auth](https://github.com/teambition/gear-auth)\n- Cookie session: [Gear-Session](https://github.com/teambition/gear-session)\n- Session middleware: [https://github.com/go-session/gear-session](https://github.com/go-session/gear-session)\n- Smart rate limiter: [Gear-Ratelimiter](https://github.com/teambition/gear-ratelimiter)\n- CSRF: [Gear-CSRF](https://github.com/teambition/gear-csrf)\n- Opentracing with Zipkin: [Gear-Tracing](https://github.com/teambition/gear-tracing)\n\n## License\n\nGear is licensed under the [MIT](https://github.com/teambition/gear/blob/master/LICENSE) license.\nCopyright \u0026copy; 2016-2023 [Teambition](https://www.teambition.com).\n","funding_links":[],"categories":["Go","Web frameworks"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fteambition%2Fgear","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fteambition%2Fgear","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fteambition%2Fgear/lists"}