{"id":13786718,"url":"https://github.com/muir/nchi","last_synced_at":"2026-01-12T12:50:20.846Z","repository":{"id":39409230,"uuid":"469601311","full_name":"muir/nchi","owner":"muir","description":"golang http router with elegance, speed, and flexibility","archived":false,"fork":false,"pushed_at":"2025-12-18T22:56:44.000Z","size":263,"stargazers_count":18,"open_issues_count":1,"forks_count":1,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-12-21T22:47:42.910Z","etag":null,"topics":["golang","http-router","middleware","rest-api"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/muir.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":".github/CODEOWNERS","security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2022-03-14T06:05:05.000Z","updated_at":"2025-12-18T22:56:47.000Z","dependencies_parsed_at":"2024-01-08T16:08:52.746Z","dependency_job_id":"50eacb63-6f88-4e1a-8f01-2dfbf25737cb","html_url":"https://github.com/muir/nchi","commit_stats":null,"previous_names":[],"tags_count":7,"template":false,"template_full_name":null,"purl":"pkg:github/muir/nchi","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/muir%2Fnchi","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/muir%2Fnchi/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/muir%2Fnchi/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/muir%2Fnchi/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/muir","download_url":"https://codeload.github.com/muir/nchi/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/muir%2Fnchi/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28338985,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-12T12:22:26.515Z","status":"ssl_error","status_checked_at":"2026-01-12T12:22:10.856Z","response_time":98,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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":["golang","http-router","middleware","rest-api"],"created_at":"2024-08-03T19:01:30.577Z","updated_at":"2026-01-12T12:50:20.841Z","avatar_url":"https://github.com/muir.png","language":"Go","readme":"# nchi - http router with speed, flexbility, and elegance\n\n[![GoDoc](https://godoc.org/github.com/muir/nchi?status.png)](https://pkg.go.dev/github.com/muir/nchi)\n![unit tests](https://github.com/muir/nchi/actions/workflows/go.yml/badge.svg)\n[![report card](https://goreportcard.com/badge/github.com/muir/nchi)](https://goreportcard.com/report/github.com/muir/nchi)\n[![codecov](https://codecov.io/gh/muir/nchi/branch/main/graph/badge.svg)](https://codecov.io/gh/muir/nchi)\n\n\u003c!---\nThis readme is heavily based upon the README.md in https://github.com/go-chi/chi.\n---\u003e\n\n`nchi` is a lightweight, elegant, and fast 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. `nchi` is built on top of the \n[nject](https://github.com/muir/nject) dependency injection framework and \nthe fastest Go http router, [httprouter](https://github.com/julienschmidt/httprouter).\n`nchi` is a straight-up rip-off of [chi](https://github.com/go-chi/chi)\nsubstituting nject for context and in the process making it easier to write middleware and\nand endpoints.\n\n`nchi` can use standard middleware and it can use dependency-injection middleware.  See:\n\n- [nvelope](https://github.com/muir/nvelope) for nject-based middleware\n- [chi](https://pkg.go.dev/github.com/go-chi/chi/middleware) for chi's middleware collection\n\nNote: if you're using `nvelope.DeferredWriter`, avoid other middleware that replaces\nthe `http.ResponseWriter`.\n\n\"Standard\" middlewhare has one of the following shapes:\n\n- `func(http.HandlerFunc) http.HandlerFunc`\n- `func(http.Handler) http.Handler`\n\n`nchi` automatically detects standard middleware and translates it for use in\nan nject-based framework.\n\n## Install\n\n\tgo get github.com/muir/nchi\n\n## Examples\n\n**As easy as:**\n\n```go\npackage main\n\nimport (\n\t\"net/http\"\n\n\t\"github.com/muir/nchi\"\n\t\"github.com/go-chi/chi/v5/middleware\"\n)\n\nfunc main() {\n\tr := nchi.NewRouter()\n\tr.Use(middleware.Logger)\n\tr.Get(\"/\", 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 how routing looks like with `nchi`. \n\n```go\nimport (\n  //...\n  \"github.com/muir/nchi\"\n  \"github.com/muir/nvelope\"\n  \"github.com/muir/nject/v2\"\n  \"github.com/go-chi/chi/v5/middleware\"\n)\n\nfunc main() {\n  r := nchi.NewRouter()\n\n  // A good base middleware stack\n  r.Use(\n     middleware.RequestID, \n     middleware.RealIP, \n     middleware.Logger,\n     nchi.DecodeJSON,\n  )\n\n  r.Use(func(inner func() error, w http.ResponseWriter) {\n     err := inner()\n     if err == nil { \n       return\n     }\n     code := nvelope.GetReturnCode(err)\n     w.WriteHeader(code)\n     w.Write([]byte(err.Error()))\n  })\n\n  // Set a timeout value on the request context (ctx), that will signal\n  // through ctx.Done() that the request has timed out and further\n  // processing should be stopped.\n  r.Use(middleware.Timeout(60 * time.Second))\n\n  r.Get(\"/\", func(w http.ResponseWriter) {\n    w.Write([]byte(\"hi\"))\n  })\n\n  // RESTy routes for \"articles\" resource\n  r.Route(\"/articles\", func(r nchi.Router) {\n    r.With(paginate).Get(\"/\", listArticles)                           // GET /articles\n    r.With(paginate).Get(\"/:month/:day/:year\", listArticlesByDate)    // GET /articles/01-16-2017\n\n    r.Post(\"/\", createArticle)                                        // POST /articles\n    r.Get(\"/search\", searchArticles)                                  // GET /articles/search\n\n    r.Get(\"/:articleSlug\", getArticleBySlug)                          // GET /articles/home-is-toronto\n\n    // Subrouters:\n    r.Route(\"/:articleID\", func(r nchi.Router) {\n      r.Use(LoadArticle)\n      r.Get(\"/\", getArticle)                                          // GET /articles/123\n      r.Put(\"/\", updateArticle)                                       // PUT /articles/123\n      r.Delete(\"/\", deleteArticle)                                    // DELETE /articles/123\n    })\n  })\n\n  // Mount the admin sub-router\n  r.Mount(\"/admin\", adminRouter())\n\n  http.ListenAndServe(\":3333\", r)\n}\n\nfunc LoadArticle(params nchi.Params) (*Article, nject.TerminalError) {\n  articleID := params.ByName(\"articleID\")\n  article, err := dbGetArticle(articleID)\n  if errors.Is(err, sql.NotFound) {\n    return nil, nvelope.NotFound(err)\n  }\n  return article, err\n}\n\nfunc getArticle(article *Article, w http.ResponseWriter) {\n  w.Write([]byte(fmt.Sprintf(\"title:%s\", article.Title)))\n}\n```\n\n## Developement status\n\n`nchi` seems to be working fine for the time being so not much is changing. Please file\nan issue if there is something you would like changed.\n","funding_links":[],"categories":["Web Frameworks","Web框架","Routers"],"sub_categories":["Routers","路由器","HTTP Clients"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmuir%2Fnchi","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmuir%2Fnchi","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmuir%2Fnchi/lists"}