[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"project-4791":3},{"id":4,"name":5,"fullName":6,"owner":7,"repo":5,"description":8,"homepage":9,"htmlUrl":10,"language":11,"languages":10,"totalLinesOfCode":10,"stars":12,"forks":13,"watchers":14,"openIssues":15,"contributorsCount":16,"subscribersCount":16,"size":16,"stars1d":17,"stars7d":18,"stars30d":19,"stars90d":16,"forks30d":16,"starsTrendScore":20,"compositeScore":21,"rankGlobal":10,"rankLanguage":10,"license":22,"archived":23,"fork":23,"defaultBranch":24,"hasWiki":25,"hasPages":23,"topics":26,"createdAt":10,"pushedAt":10,"updatedAt":36,"readmeContent":37,"aiSummary":38,"trendingCount":16,"starSnapshotCount":16,"syncStatus":39,"lastSyncTime":40,"discoverSource":41},4791,"chi","go-chi\u002Fchi","go-chi","lightweight, idiomatic and composable router for building Go HTTP services","https:\u002F\u002Fgo-chi.io",null,"Go",22339,1115,202,58,0,5,48,213,30,44.14,"MIT License",false,"master",true,[27,28,29,30,31,32,33,34,35],"api","context","go","golang","http","microservices","middleware","rest-api","router","2026-06-12 02:01:03","# \u003Cimg alt=\"chi\" src=\"https:\u002F\u002Fcdn.rawgit.com\u002Fgo-chi\u002Fchi\u002Fmaster\u002F_examples\u002Fchi.svg\" width=\"220\" \u002F>\n\n\n[![GoDoc Widget]][GoDoc]\n\n`chi` is a lightweight, idiomatic and composable router for building Go HTTP services. It's\nespecially good at helping you write large REST API services that are kept maintainable as your\nproject grows and changes. `chi` is built on the new `context` package introduced in Go 1.7 to\nhandle signaling, cancelation and request-scoped values across a handler chain.\n\nThe focus of the project has been to seek out an elegant and comfortable design for writing\nREST API servers, written during the development of the Pressly API service that powers our\npublic API service, which in turn powers all of our client-side applications.\n\nThe key considerations of chi's design are: project structure, maintainability, standard http\nhandlers (stdlib-only), developer productivity, and deconstructing a large system into many small\nparts. The core router `github.com\u002Fgo-chi\u002Fchi` is quite small (less than 1000 LOC), but we've also\nincluded some useful\u002Foptional subpackages: [middleware](\u002Fmiddleware), [render](https:\u002F\u002Fgithub.com\u002Fgo-chi\u002Frender)\nand [docgen](https:\u002F\u002Fgithub.com\u002Fgo-chi\u002Fdocgen). We hope you enjoy it too!\n\n## Install\n\n```sh\ngo get -u github.com\u002Fgo-chi\u002Fchi\u002Fv5\n```\n\n\n## Features\n\n* **Lightweight** - cloc'd in ~1000 LOC for the chi router\n* **Fast** - yes, see [benchmarks](#benchmarks)\n* **100% compatible with net\u002Fhttp** - use any http or middleware pkg in the ecosystem that is also compatible with `net\u002Fhttp`\n* **Designed for modular\u002Fcomposable APIs** - middlewares, inline middlewares, route groups and sub-router mounting\n* **Context control** - built on new `context` package, providing value chaining, cancellations and timeouts\n* **Robust** - in production at Pressly, Cloudflare, Heroku, 99Designs, and many others (see [discussion](https:\u002F\u002Fgithub.com\u002Fgo-chi\u002Fchi\u002Fissues\u002F91))\n* **Doc generation** - `docgen` auto-generates routing documentation from your source to JSON or Markdown\n* **Go.mod support** - as of v5, go.mod support (see [CHANGELOG](https:\u002F\u002Fgithub.com\u002Fgo-chi\u002Fchi\u002Fblob\u002Fmaster\u002FCHANGELOG.md))\n* **No external dependencies** - plain ol' Go stdlib + net\u002Fhttp\n\n\n## Examples\n\nSee [_examples\u002F](https:\u002F\u002Fgithub.com\u002Fgo-chi\u002Fchi\u002Fblob\u002Fmaster\u002F_examples\u002F) for a variety of examples.\n\n\n**As easy as:**\n\n```go\npackage main\n\nimport (\n\t\"net\u002Fhttp\"\n\n\t\"github.com\u002Fgo-chi\u002Fchi\u002Fv5\"\n\t\"github.com\u002Fgo-chi\u002Fchi\u002Fv5\u002Fmiddleware\"\n)\n\nfunc main() {\n\tr := chi.NewRouter()\n\tr.Use(middleware.Logger)\n\tr.Get(\"\u002F\", func(w http.ResponseWriter, r *http.Request) {\n\t\tw.Write([]byte(\"welcome\"))\n\t})\n\thttp.ListenAndServe(\":3000\", r)\n}\n```\n\n**REST Preview:**\n\nHere is a little preview of what routing looks like with chi. Also take a look at the generated routing docs\nin JSON ([routes.json](https:\u002F\u002Fgithub.com\u002Fgo-chi\u002Fchi\u002Fblob\u002Fmaster\u002F_examples\u002Frest\u002Froutes.json)) and in\nMarkdown ([routes.md](https:\u002F\u002Fgithub.com\u002Fgo-chi\u002Fchi\u002Fblob\u002Fmaster\u002F_examples\u002Frest\u002Froutes.md)).\n\nI highly recommend reading the source of the [examples](https:\u002F\u002Fgithub.com\u002Fgo-chi\u002Fchi\u002Fblob\u002Fmaster\u002F_examples\u002F) listed\nabove, they will show you all the features of chi and serve as a good form of documentation.\n\n```go\nimport (\n  \u002F\u002F...\n  \"context\"\n  \"github.com\u002Fgo-chi\u002Fchi\u002Fv5\"\n  \"github.com\u002Fgo-chi\u002Fchi\u002Fv5\u002Fmiddleware\"\n)\n\nfunc main() {\n  r := chi.NewRouter()\n\n  \u002F\u002F A good base middleware stack\n  r.Use(middleware.RequestID)\n  r.Use(middleware.RealIP)\n  r.Use(middleware.Logger)\n  r.Use(middleware.Recoverer)\n\n  \u002F\u002F Set a timeout value on the request context (ctx), that will signal\n  \u002F\u002F through ctx.Done() that the request has timed out and further\n  \u002F\u002F processing should be stopped.\n  r.Use(middleware.Timeout(60 * time.Second))\n\n  r.Get(\"\u002F\", func(w http.ResponseWriter, r *http.Request) {\n    w.Write([]byte(\"hi\"))\n  })\n\n  \u002F\u002F RESTy routes for \"articles\" resource\n  r.Route(\"\u002Farticles\", func(r chi.Router) {\n    r.With(paginate).Get(\"\u002F\", listArticles)                           \u002F\u002F GET \u002Farticles\n    r.With(paginate).Get(\"\u002F{month}-{day}-{year}\", listArticlesByDate) \u002F\u002F GET \u002Farticles\u002F01-16-2017\n\n    r.Post(\"\u002F\", createArticle)                                        \u002F\u002F POST \u002Farticles\n    r.Get(\"\u002Fsearch\", searchArticles)                                  \u002F\u002F GET \u002Farticles\u002Fsearch\n\n    \u002F\u002F Regexp url parameters:\n    r.Get(\"\u002F{articleSlug:[a-z-]+}\", getArticleBySlug)                \u002F\u002F GET \u002Farticles\u002Fhome-is-toronto\n\n    \u002F\u002F Subrouters:\n    r.Route(\"\u002F{articleID}\", func(r chi.Router) {\n      r.Use(ArticleCtx)\n      r.Get(\"\u002F\", getArticle)                                          \u002F\u002F GET \u002Farticles\u002F123\n      r.Put(\"\u002F\", updateArticle)                                       \u002F\u002F PUT \u002Farticles\u002F123\n      r.Delete(\"\u002F\", deleteArticle)                                    \u002F\u002F DELETE \u002Farticles\u002F123\n    })\n  })\n\n  \u002F\u002F Mount the admin sub-router\n  r.Mount(\"\u002Fadmin\", adminRouter())\n\n  http.ListenAndServe(\":3333\", r)\n}\n\nfunc ArticleCtx(next http.Handler) http.Handler {\n  return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {\n    articleID := chi.URLParam(r, \"articleID\")\n    article, err := dbGetArticle(articleID)\n    if err != nil {\n      http.Error(w, http.StatusText(404), 404)\n      return\n    }\n    ctx := context.WithValue(r.Context(), \"article\", article)\n    next.ServeHTTP(w, r.WithContext(ctx))\n  })\n}\n\nfunc getArticle(w http.ResponseWriter, r *http.Request) {\n  ctx := r.Context()\n  article, ok := ctx.Value(\"article\").(*Article)\n  if !ok {\n    http.Error(w, http.StatusText(422), 422)\n    return\n  }\n  w.Write([]byte(fmt.Sprintf(\"title:%s\", article.Title)))\n}\n\n\u002F\u002F A completely separate router for administrator routes\nfunc adminRouter() http.Handler {\n  r := chi.NewRouter()\n  r.Use(AdminOnly)\n  r.Get(\"\u002F\", adminIndex)\n  r.Get(\"\u002Faccounts\", adminListAccounts)\n  return r\n}\n\nfunc AdminOnly(next http.Handler) http.Handler {\n  return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {\n    ctx := r.Context()\n    perm, ok := ctx.Value(\"acl.permission\").(YourPermissionType)\n    if !ok || !perm.IsAdmin() {\n      http.Error(w, http.StatusText(403), 403)\n      return\n    }\n    next.ServeHTTP(w, r)\n  })\n}\n```\n\n\n## Router interface\n\nchi's router is based on a kind of [Patricia Radix trie](https:\u002F\u002Fen.wikipedia.org\u002Fwiki\u002FRadix_tree).\nThe router is fully compatible with `net\u002Fhttp`.\n\nBuilt on top of the tree is the `Router` interface:\n\n```go\n\u002F\u002F Router consisting of the core routing methods used by chi's Mux,\n\u002F\u002F using only the standard net\u002Fhttp.\ntype Router interface {\n\thttp.Handler\n\tRoutes\n\n\t\u002F\u002F Use appends one or more middlewares onto the Router stack.\n\tUse(middlewares ...func(http.Handler) http.Handler)\n\n\t\u002F\u002F With adds inline middlewares for an endpoint handler.\n\tWith(middlewares ...func(http.Handler) http.Handler) Router\n\n\t\u002F\u002F Group adds a new inline-Router along the current routing\n\t\u002F\u002F path, with a fresh middleware stack for the inline-Router.\n\tGroup(fn func(r Router)) Router\n\n\t\u002F\u002F Route mounts a sub-Router along a `pattern` string.\n\tRoute(pattern string, fn func(r Router)) Router\n\n\t\u002F\u002F Mount attaches another http.Handler along .\u002Fpattern\u002F*\n\tMount(pattern string, h http.Handler)\n\n\t\u002F\u002F Handle and HandleFunc adds routes for `pattern` that matches\n\t\u002F\u002F all HTTP methods.\n\tHandle(pattern string, h http.Handler)\n\tHandleFunc(pattern string, h http.HandlerFunc)\n\n\t\u002F\u002F Method and MethodFunc adds routes for `pattern` that matches\n\t\u002F\u002F the `method` HTTP method.\n\tMethod(method, pattern string, h http.Handler)\n\tMethodFunc(method, pattern string, h http.HandlerFunc)\n\n\t\u002F\u002F HTTP-method routing along `pattern`\n\tConnect(pattern string, h http.HandlerFunc)\n\tDelete(pattern string, h http.HandlerFunc)\n\tGet(pattern string, h http.HandlerFunc)\n\tHead(pattern string, h http.HandlerFunc)\n\tOptions(pattern string, h http.HandlerFunc)\n\tPatch(pattern string, h http.HandlerFunc)\n\tPost(pattern string, h http.HandlerFunc)\n\tPut(pattern string, h http.HandlerFunc)\n\tTrace(pattern string, h http.HandlerFunc)\n\n\t\u002F\u002F NotFound defines a handler to respond whenever a route could\n\t\u002F\u002F not be found.\n\tNotFound(h http.HandlerFunc)\n\n\t\u002F\u002F MethodNotAllowed defines a handler to respond whenever a method is\n\t\u002F\u002F not allowed.\n\tMethodNotAllowed(h http.HandlerFunc)\n}\n\n\u002F\u002F Routes interface adds two methods for router traversal, which is also\n\u002F\u002F used by the github.com\u002Fgo-chi\u002Fdocgen package to generate documentation for Routers.\ntype Routes interface {\n\t\u002F\u002F Routes returns the routing tree in an easily traversable structure.\n\tRoutes() []Route\n\n\t\u002F\u002F Middlewares returns the list of middlewares in use by the router.\n\tMiddlewares() Middlewares\n\n\t\u002F\u002F Match searches the routing tree for a handler that matches\n\t\u002F\u002F the method\u002Fpath - similar to routing a http request, but without\n\t\u002F\u002F executing the handler thereafter.\n\tMatch(rctx *Context, method, path string) bool\n}\n```\n\nEach routing method accepts a URL `pattern` and chain of `handlers`. The URL pattern\nsupports named params (ie. `\u002Fusers\u002F{userID}`) and wildcards (ie. `\u002Fadmin\u002F*`). URL parameters\ncan be fetched at runtime by calling `chi.URLParam(r, \"userID\")` for named parameters\nand `chi.URLParam(r, \"*\")` for a wildcard parameter.\n\n\n### Middleware handlers\n\nchi's middlewares are just stdlib net\u002Fhttp middleware handlers. There is nothing special\nabout them, which means the router and all the tooling is designed to be compatible and\nfriendly with any middleware in the community. This offers much better extensibility and reuse\nof packages and is at the heart of chi's purpose.\n\nHere is an example of a standard net\u002Fhttp middleware where we assign a context key `\"user\"`\nthe value of `\"123\"`. This middleware sets a hypothetical user identifier on the request\ncontext and calls the next handler in the chain.\n\n```go\n\u002F\u002F HTTP middleware setting a value on the request context\nfunc MyMiddleware(next http.Handler) http.Handler {\n  return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {\n    \u002F\u002F create new context from `r` request context, and assign key `\"user\"`\n    \u002F\u002F to value of `\"123\"`\n    ctx := context.WithValue(r.Context(), \"user\", \"123\")\n\n    \u002F\u002F call the next handler in the chain, passing the response writer and\n    \u002F\u002F the updated request object with the new context value.\n    \u002F\u002F\n    \u002F\u002F note: context.Context values are nested, so any previously set\n    \u002F\u002F values will be accessible as well, and the new `\"user\"` key\n    \u002F\u002F will be accessible from this point forward.\n    next.ServeHTTP(w, r.WithContext(ctx))\n  })\n}\n```\n\n\n### Request handlers\n\nchi uses standard net\u002Fhttp request handlers. This little snippet is an example of a http.Handler\nfunc that reads a user identifier from the request context - hypothetically, identifying\nthe user sending an authenticated request, validated+set by a previous middleware handler.\n\n```go\n\u002F\u002F HTTP handler accessing data from the request context.\nfunc MyRequestHandler(w http.ResponseWriter, r *http.Request) {\n  \u002F\u002F here we read from the request context and fetch out `\"user\"` key set in\n  \u002F\u002F the MyMiddleware example above.\n  user := r.Context().Value(\"user\").(string)\n\n  \u002F\u002F respond to the client\n  w.Write([]byte(fmt.Sprintf(\"hi %s\", user)))\n}\n```\n\n\n### URL parameters\n\nchi's router parses and stores URL parameters right onto the request context. Here is\nan example of how to access URL params in your net\u002Fhttp handlers. And of course, middlewares\nare able to access the same information.\n\n```go\n\u002F\u002F HTTP handler accessing the url routing parameters.\nfunc MyRequestHandler(w http.ResponseWriter, r *http.Request) {\n  \u002F\u002F fetch the url parameter `\"userID\"` from the request of a matching\n  \u002F\u002F routing pattern. An example routing pattern could be: \u002Fusers\u002F{userID}\n  userID := chi.URLParam(r, \"userID\")\n\n  \u002F\u002F fetch `\"key\"` from the request context\n  ctx := r.Context()\n  key := ctx.Value(\"key\").(string)\n\n  \u002F\u002F respond to the client\n  w.Write([]byte(fmt.Sprintf(\"hi %v, %v\", userID, key)))\n}\n```\n\n\n## Middlewares\n\nchi comes equipped with an optional `middleware` package, providing a suite of standard\n`net\u002Fhttp` middlewares. Please note, any middleware in the ecosystem that is also compatible\nwith `net\u002Fhttp` can be used with chi's mux.\n\n### Core middlewares\n\n----------------------------------------------------------------------------------------------------\n| chi\u002Fmiddleware Handler | description                                                             |\n| :--------------------- | :---------------------------------------------------------------------- |\n| [AllowContentEncoding] | Enforces a whitelist of request Content-Encoding headers                |\n| [AllowContentType]     | Explicit whitelist of accepted request Content-Types                    |\n| [BasicAuth]            | Basic HTTP authentication                                               |\n| [Compress]             | Gzip compression for clients that accept compressed responses           |\n| [ContentCharset]       | Ensure charset for Content-Type request headers                         |\n| [CleanPath]            | Clean double slashes from request path                                  |\n| [GetHead]              | Automatically route undefined HEAD requests to GET handlers             |\n| [Heartbeat]            | Monitoring endpoint to check the servers pulse                          |\n| [Logger]               | Logs the start and end of each request with the elapsed processing time |\n| [NoCache]              | Sets response headers to prevent clients from caching                   |\n| [Profiler]             | Easily attach net\u002Fhttp\u002Fpprof to your routers                            |\n| [RealIP]               | Sets a http.Request's RemoteAddr to either X-Real-IP or X-Forwarded-For |\n| [Recoverer]            | Gracefully absorb panics and prints the stack trace                     |\n| [RequestID]            | Injects a request ID into the context of each request                   |\n| [RedirectSlashes]      | Redirect slashes on routing paths                                       |\n| [RouteHeaders]         | Route handling for request headers                                      |\n| [SetHeader]            | Short-hand middleware to set a response header key\u002Fvalue                |\n| [StripSlashes]         | Strip slashes on routing paths                                          |\n| [Sunset]               | Sunset set Deprecation\u002FSunset header to response                        |\n| [Throttle]             | Puts a ceiling on the number of concurrent requests                     |\n| [Timeout]              | Signals to the request context when the timeout deadline is reached     |\n| [URLFormat]            | Parse extension from url and put it on request context                  |\n| [WithValue]            | Short-hand middleware to set a key\u002Fvalue on the request context         |\n----------------------------------------------------------------------------------------------------\n\n[AllowContentEncoding]: https:\u002F\u002Fpkg.go.dev\u002Fgithub.com\u002Fgo-chi\u002Fchi\u002Fmiddleware#AllowContentEncoding\n[AllowContentType]: https:\u002F\u002Fpkg.go.dev\u002Fgithub.com\u002Fgo-chi\u002Fchi\u002Fmiddleware#AllowContentType\n[BasicAuth]: https:\u002F\u002Fpkg.go.dev\u002Fgithub.com\u002Fgo-chi\u002Fchi\u002Fmiddleware#BasicAuth\n[Compress]: https:\u002F\u002Fpkg.go.dev\u002Fgithub.com\u002Fgo-chi\u002Fchi\u002Fmiddleware#Compress\n[ContentCharset]: https:\u002F\u002Fpkg.go.dev\u002Fgithub.com\u002Fgo-chi\u002Fchi\u002Fmiddleware#ContentCharset\n[CleanPath]: https:\u002F\u002Fpkg.go.dev\u002Fgithub.com\u002Fgo-chi\u002Fchi\u002Fmiddleware#CleanPath\n[GetHead]: https:\u002F\u002Fpkg.go.dev\u002Fgithub.com\u002Fgo-chi\u002Fchi\u002Fmiddleware#GetHead\n[GetReqID]: https:\u002F\u002Fpkg.go.dev\u002Fgithub.com\u002Fgo-chi\u002Fchi\u002Fmiddleware#GetReqID\n[Heartbeat]: https:\u002F\u002Fpkg.go.dev\u002Fgithub.com\u002Fgo-chi\u002Fchi\u002Fmiddleware#Heartbeat\n[Logger]: https:\u002F\u002Fpkg.go.dev\u002Fgithub.com\u002Fgo-chi\u002Fchi\u002Fmiddleware#Logger\n[NoCache]: https:\u002F\u002Fpkg.go.dev\u002Fgithub.com\u002Fgo-chi\u002Fchi\u002Fmiddleware#NoCache\n[Profiler]: https:\u002F\u002Fpkg.go.dev\u002Fgithub.com\u002Fgo-chi\u002Fchi\u002Fmiddleware#Profiler\n[RealIP]: https:\u002F\u002Fpkg.go.dev\u002Fgithub.com\u002Fgo-chi\u002Fchi\u002Fmiddleware#RealIP\n[Recoverer]: https:\u002F\u002Fpkg.go.dev\u002Fgithub.com\u002Fgo-chi\u002Fchi\u002Fmiddleware#Recoverer\n[RedirectSlashes]: https:\u002F\u002Fpkg.go.dev\u002Fgithub.com\u002Fgo-chi\u002Fchi\u002Fmiddleware#RedirectSlashes\n[RequestLogger]: https:\u002F\u002Fpkg.go.dev\u002Fgithub.com\u002Fgo-chi\u002Fchi\u002Fmiddleware#RequestLogger\n[RequestID]: https:\u002F\u002Fpkg.go.dev\u002Fgithub.com\u002Fgo-chi\u002Fchi\u002Fmiddleware#RequestID\n[RouteHeaders]: https:\u002F\u002Fpkg.go.dev\u002Fgithub.com\u002Fgo-chi\u002Fchi\u002Fmiddleware#RouteHeaders\n[SetHeader]: https:\u002F\u002Fpkg.go.dev\u002Fgithub.com\u002Fgo-chi\u002Fchi\u002Fmiddleware#SetHeader\n[StripSlashes]: https:\u002F\u002Fpkg.go.dev\u002Fgithub.com\u002Fgo-chi\u002Fchi\u002Fmiddleware#StripSlashes\n[Sunset]: https:\u002F\u002Fpkg.go.dev\u002Fgithub.com\u002Fgo-chi\u002Fchi\u002Fv5\u002Fmiddleware#Sunset\n[Throttle]: https:\u002F\u002Fpkg.go.dev\u002Fgithub.com\u002Fgo-chi\u002Fchi\u002Fmiddleware#Throttle\n[ThrottleBacklog]: https:\u002F\u002Fpkg.go.dev\u002Fgithub.com\u002Fgo-chi\u002Fchi\u002Fmiddleware#ThrottleBacklog\n[ThrottleWithOpts]: https:\u002F\u002Fpkg.go.dev\u002Fgithub.com\u002Fgo-chi\u002Fchi\u002Fmiddleware#ThrottleWithOpts\n[Timeout]: https:\u002F\u002Fpkg.go.dev\u002Fgithub.com\u002Fgo-chi\u002Fchi\u002Fmiddleware#Timeout\n[URLFormat]: https:\u002F\u002Fpkg.go.dev\u002Fgithub.com\u002Fgo-chi\u002Fchi\u002Fmiddleware#URLFormat\n[WithLogEntry]: https:\u002F\u002Fpkg.go.dev\u002Fgithub.com\u002Fgo-chi\u002Fchi\u002Fmiddleware#WithLogEntry\n[WithValue]: https:\u002F\u002Fpkg.go.dev\u002Fgithub.com\u002Fgo-chi\u002Fchi\u002Fmiddleware#WithValue\n[Compressor]: https:\u002F\u002Fpkg.go.dev\u002Fgithub.com\u002Fgo-chi\u002Fchi\u002Fmiddleware#Compressor\n[DefaultLogFormatter]: https:\u002F\u002Fpkg.go.dev\u002Fgithub.com\u002Fgo-chi\u002Fchi\u002Fmiddleware#DefaultLogFormatter\n[EncoderFunc]: https:\u002F\u002Fpkg.go.dev\u002Fgithub.com\u002Fgo-chi\u002Fchi\u002Fmiddleware#EncoderFunc\n[HeaderRoute]: https:\u002F\u002Fpkg.go.dev\u002Fgithub.com\u002Fgo-chi\u002Fchi\u002Fmiddleware#HeaderRoute\n[HeaderRouter]: https:\u002F\u002Fpkg.go.dev\u002Fgithub.com\u002Fgo-chi\u002Fchi\u002Fmiddleware#HeaderRouter\n[LogEntry]: https:\u002F\u002Fpkg.go.dev\u002Fgithub.com\u002Fgo-chi\u002Fchi\u002Fmiddleware#LogEntry\n[LogFormatter]: https:\u002F\u002Fpkg.go.dev\u002Fgithub.com\u002Fgo-chi\u002Fchi\u002Fmiddleware#LogFormatter\n[LoggerInterface]: https:\u002F\u002Fpkg.go.dev\u002Fgithub.com\u002Fgo-chi\u002Fchi\u002Fmiddleware#LoggerInterface\n[ThrottleOpts]: https:\u002F\u002Fpkg.go.dev\u002Fgithub.com\u002Fgo-chi\u002Fchi\u002Fmiddleware#ThrottleOpts\n[WrapResponseWriter]: https:\u002F\u002Fpkg.go.dev\u002Fgithub.com\u002Fgo-chi\u002Fchi\u002Fmiddleware#WrapResponseWriter\n\n### Extra middlewares & packages\n\nPlease see https:\u002F\u002Fgithub.com\u002Fgo-chi for additional packages.\n\n--------------------------------------------------------------------------------------------------------------------\n| package                                            | description                                                 |\n|:---------------------------------------------------|:-------------------------------------------------------------\n| [cors](https:\u002F\u002Fgithub.com\u002Fgo-chi\u002Fcors)             | Cross-origin resource sharing (CORS)                        |\n| [docgen](https:\u002F\u002Fgithub.com\u002Fgo-chi\u002Fdocgen)         | Print chi.Router routes at runtime                          |\n| [jwtauth](https:\u002F\u002Fgithub.com\u002Fgo-chi\u002Fjwtauth)       | JWT authentication                                          |\n| [hostrouter](https:\u002F\u002Fgithub.com\u002Fgo-chi\u002Fhostrouter) | Domain\u002Fhost based request routing                           |\n| [httplog](https:\u002F\u002Fgithub.com\u002Fgo-chi\u002Fhttplog)       | Small but powerful structured HTTP request logging          |\n| [httprate](https:\u002F\u002Fgithub.com\u002Fgo-chi\u002Fhttprate)     | HTTP request rate limiter                                   |\n| [httptracer](https:\u002F\u002Fgithub.com\u002Fgo-chi\u002Fhttptracer) | HTTP request performance tracing library                    |\n| [httpvcr](https:\u002F\u002Fgithub.com\u002Fgo-chi\u002Fhttpvcr)       | Write deterministic tests for external sources              |\n| [stampede](https:\u002F\u002Fgithub.com\u002Fgo-chi\u002Fstampede)     | HTTP request coalescer                                      |\n--------------------------------------------------------------------------------------------------------------------\n\n\n## context?\n\n`context` is a tiny pkg that provides simple interface to signal context across call stacks\nand goroutines. It was originally written by [Sameer Ajmani](https:\u002F\u002Fgithub.com\u002FSajmani)\nand is available in stdlib since go1.7.\n\nLearn more at https:\u002F\u002Fblog.golang.org\u002Fcontext\n\nand..\n* Docs: https:\u002F\u002Fgolang.org\u002Fpkg\u002Fcontext\n* Source: https:\u002F\u002Fgithub.com\u002Fgolang\u002Fgo\u002Ftree\u002Fmaster\u002Fsrc\u002Fcontext\n\n\n## Benchmarks\n\nThe benchmark suite: https:\u002F\u002Fgithub.com\u002Fpkieltyka\u002Fgo-http-routing-benchmark\n\nResults as of Nov 29, 2020 with Go 1.15.5 on Linux AMD 3950x\n\n```shell\nBenchmarkChi_Param          \t3075895\t        384 ns\u002Fop\t      400 B\u002Fop      2 allocs\u002Fop\nBenchmarkChi_Param5         \t2116603\t        566 ns\u002Fop\t      400 B\u002Fop      2 allocs\u002Fop\nBenchmarkChi_Param20        \t 964117\t       1227 ns\u002Fop\t      400 B\u002Fop      2 allocs\u002Fop\nBenchmarkChi_ParamWrite     \t2863413\t        420 ns\u002Fop\t      400 B\u002Fop      2 allocs\u002Fop\nBenchmarkChi_GithubStatic   \t3045488\t        395 ns\u002Fop\t      400 B\u002Fop      2 allocs\u002Fop\nBenchmarkChi_GithubParam    \t2204115\t        540 ns\u002Fop\t      400 B\u002Fop      2 allocs\u002Fop\nBenchmarkChi_GithubAll      \t  10000\t     113811 ns\u002Fop\t    81203 B\u002Fop    406 allocs\u002Fop\nBenchmarkChi_GPlusStatic    \t3337485\t        359 ns\u002Fop\t      400 B\u002Fop      2 allocs\u002Fop\nBenchmarkChi_GPlusParam     \t2825853\t        423 ns\u002Fop\t      400 B\u002Fop      2 allocs\u002Fop\nBenchmarkChi_GPlus2Params   \t2471697\t        483 ns\u002Fop\t      400 B\u002Fop      2 allocs\u002Fop\nBenchmarkChi_GPlusAll       \t 194220\t       5950 ns\u002Fop\t     5200 B\u002Fop     26 allocs\u002Fop\nBenchmarkChi_ParseStatic    \t3365324\t        356 ns\u002Fop\t      400 B\u002Fop      2 allocs\u002Fop\nBenchmarkChi_ParseParam     \t2976614\t        404 ns\u002Fop\t      400 B\u002Fop      2 allocs\u002Fop\nBenchmarkChi_Parse2Params   \t2638084\t        439 ns\u002Fop\t      400 B\u002Fop      2 allocs\u002Fop\nBenchmarkChi_ParseAll       \t 109567\t      11295 ns\u002Fop\t    10400 B\u002Fop     52 allocs\u002Fop\nBenchmarkChi_StaticAll      \t  16846\t      71308 ns\u002Fop\t    62802 B\u002Fop    314 allocs\u002Fop\n```\n\nComparison with other routers: https:\u002F\u002Fgist.github.com\u002Fpkieltyka\u002F123032f12052520aaccab752bd3e78cc\n\nNOTE: the allocs in the benchmark above are from the calls to http.Request's\n`WithContext(context.Context)` method that clones the http.Request, sets the `Context()`\non the duplicated (alloc'd) request and returns it the new request object. This is just\nhow setting context on a request in Go works.\n\n\n## Credits\n\n* Carl Jackson for https:\u002F\u002Fgithub.com\u002Fzenazn\u002Fgoji\n  * Parts of chi's thinking comes from goji, and chi's middleware package\n    sources from [goji](https:\u002F\u002Fgithub.com\u002Fzenazn\u002Fgoji\u002Ftree\u002Fmaster\u002Fweb\u002Fmiddleware).\n  * Please see goji's [LICENSE](https:\u002F\u002Fgithub.com\u002Fzenazn\u002Fgoji\u002Fblob\u002Fmaster\u002FLICENSE) (MIT)\n* Armon Dadgar for https:\u002F\u002Fgithub.com\u002Farmon\u002Fgo-radix\n* Contributions: [@VojtechVitek](https:\u002F\u002Fgithub.com\u002FVojtechVitek)\n\nWe'll be more than happy to see [your contributions](.\u002FCONTRIBUTING.md)!\n\n\n## Beyond REST\n\nchi is just a http router that lets you decompose request handling into many smaller layers.\nMany companies use chi to write REST services for their public APIs. But, REST is just a convention\nfor managing state via HTTP, and there's a lot of other pieces required to write a complete client-server\nsystem or network of microservices.\n\nLooking beyond REST, I also recommend some newer works in the field:\n* [webrpc](https:\u002F\u002Fgithub.com\u002Fwebrpc\u002Fwebrpc) - Web-focused RPC client+server framework with code-gen\n* [gRPC](https:\u002F\u002Fgithub.com\u002Fgrpc\u002Fgrpc-go) - Google's RPC framework via protobufs\n* [graphql](https:\u002F\u002Fgithub.com\u002F99designs\u002Fgqlgen) - Declarative query language\n* [NATS](https:\u002F\u002Fnats.io) - lightweight pub-sub\n\n\n## License\n\nCopyright (c) 2015-present [Peter Kieltyka](https:\u002F\u002Fgithub.com\u002Fpkieltyka)\n\nLicensed under [MIT License](.\u002FLICENSE)\n\n[GoDoc]: https:\u002F\u002Fpkg.go.dev\u002Fgithub.com\u002Fgo-chi\u002Fchi\u002Fv5\n[GoDoc Widget]: https:\u002F\u002Fgodoc.org\u002Fgithub.com\u002Fgo-chi\u002Fchi?status.svg\n[Travis]: https:\u002F\u002Ftravis-ci.org\u002Fgo-chi\u002Fchi\n[Travis Widget]: https:\u002F\u002Ftravis-ci.org\u002Fgo-chi\u002Fchi.svg?branch=master\n","chi 是一个轻量级、惯用且可组合的路由器，用于构建 Go HTTP 服务。它特别适合于开发大型 REST API 服务，并保持项目在增长和变化时的可维护性。chi 基于 Go 1.7 引入的新 `context` 包构建，支持信号传递、取消操作和请求范围值的管理。该项目专注于优雅的设计，以提高开发者生产力并简化复杂系统的分解。chi 路由器本身非常小巧（不到 1000 行代码），同时提供了有用的中间件、渲染工具和文档生成等子包。它完全兼容标准库 `net\u002Fhttp`，并且没有外部依赖，非常适合需要高性能和模块化设计的 Web 服务场景。",2,"2026-06-11 03:00:30","top_language"]