{"id":13393350,"url":"https://github.com/VividCortex/siesta","last_synced_at":"2025-03-13T19:31:33.287Z","repository":{"id":21074002,"uuid":"24373540","full_name":"VividCortex/siesta","owner":"VividCortex","description":"Composable framework for writing HTTP handlers in Go.","archived":false,"fork":false,"pushed_at":"2023-12-12T11:21:05.000Z","size":83,"stargazers_count":349,"open_issues_count":0,"forks_count":15,"subscribers_count":30,"default_branch":"master","last_synced_at":"2024-10-26T18:29:55.470Z","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/VividCortex.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,"governance":null,"roadmap":null,"authors":null}},"created_at":"2014-09-23T13:55:56.000Z","updated_at":"2024-08-22T14:04:04.000Z","dependencies_parsed_at":"2024-01-08T16:08:52.285Z","dependency_job_id":"c3a0f729-f5ed-4beb-a5bb-3b6d6960403f","html_url":"https://github.com/VividCortex/siesta","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/VividCortex%2Fsiesta","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/VividCortex%2Fsiesta/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/VividCortex%2Fsiesta/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/VividCortex%2Fsiesta/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/VividCortex","download_url":"https://codeload.github.com/VividCortex/siesta/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243469160,"owners_count":20295699,"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-07-30T17:00:50.910Z","updated_at":"2025-03-13T19:31:32.925Z","avatar_url":"https://github.com/VividCortex.png","language":"Go","readme":"# siesta\n\n[![GoDoc](https://godoc.org/github.com/VividCortex/siesta?status.svg)](https://godoc.org/github.com/VividCortex/siesta)\n![build](https://github.com/VividCortex/siesta/workflows/build/badge.svg)\n[![codecov](https://codecov.io/gh/VividCortex/siesta/branch/master/graph/badge.svg)](https://codecov.io/gh/VividCortex/siesta)\n\nSiesta is a framework for writing composable HTTP handlers in Go. It supports typed URL parameters, middleware chains, and context passing.\n\n## Getting started\n\nSiesta offers a `Service` type, which is a collection of middleware chains and handlers rooted at a base URI. There is no distinction between a middleware function and a handler function; they are all considered to be handlers and have access to the same arguments.\n\nSiesta accepts many types of handlers. Refer to the [GoDoc](https://godoc.org/github.com/VividCortex/siesta#Service.Route) documentation for `Service.Route` for more information.\n\nHere is the `simple` program in the examples directory. It demonstrates the use of a `Service`, routing, middleware, and a `Context`.\n\n```go\npackage main\n\nimport (\n\t\"fmt\"\n\t\"log\"\n\t\"net/http\"\n\t\"time\"\n\n\t\"github.com/VividCortex/siesta\"\n)\n\nfunc main() {\n\t// Create a new Service rooted at \"/\"\n\tservice := siesta.NewService(\"/\")\n\n\t// Route accepts normal http.Handlers.\n\t// The arguments are the method, path, description,\n\t// and the handler.\n\tservice.Route(\"GET\", \"/\", \"Sends 'Hello, world!'\",\n\t\tfunc(w http.ResponseWriter, r *http.Request) {\n\t\tfmt.Fprintln(w, \"Hello, world!\")\n\t})\n\n\t// Let's create some simple \"middleware.\"\n\t// This handler will accept a Context argument and will add the current\n\t// time to it.\n\ttimestamper := func(c siesta.Context, w http.ResponseWriter, r *http.Request) {\n\t\tc.Set(\"start\", time.Now())\n\t}\n\n\t// This is the handler that will actually send data back to the client.\n\t// It also takes a Context argument so it can get the timestamp from the\n\t// previous handler.\n\ttimeHandler := func(c siesta.Context, w http.ResponseWriter, r *http.Request) {\n\t\tstart := c.Get(\"start\").(time.Time)\n\t\tdelta := time.Now().Sub(start)\n\t\tfmt.Fprintf(w, \"That took %v.\\n\", delta)\n\t}\n\n\t// We can compose these handlers together.\n\ttimeHandlers := siesta.Compose(timestamper, timeHandler)\n\n\t// Finally, we'll add the new handler we created using composition to a new route.\n\tservice.Route(\"GET\", \"/time\", \"Sends how long it took to send a message\", timeHandlers)\n\n\t// service is an http.Handler, so we can pass it directly to ListenAndServe.\n\tlog.Fatal(http.ListenAndServe(\":8080\", service))\n}\n```\n\nSiesta also provides utilities to manage URL parameters similar to the flag package. Refer to the `params` [example](https://github.com/VividCortex/siesta/blob/master/examples/params/main.go) for a demonstration.\n\n## Contributing\n\nWe only accept pull requests for minor fixes or improvements. This includes:\n\n* Small bug fixes\n* Typos\n* Documentation or comments\n\nPlease open issues to discuss new features. Pull requests for new features will be rejected,\nso we recommend forking the repository and making changes in your fork for your use case.\n\n## License\n\nSiesta is licensed under the MIT license. The router, which is adapted from [httprouter](https://github.com/julienschmidt/httprouter), is licensed [separately](https://github.com/VividCortex/siesta/blob/6ce42bf31875cc845310b1f4775129edfc8d9967/tree.go#L2-L24).\n","funding_links":[],"categories":["Go","Web Frameworks","Routers","Web框架","XML","路由"],"sub_categories":["Advanced Console UIs","Routers","路由器","路由","创建http中间件的代码库"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FVividCortex%2Fsiesta","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FVividCortex%2Fsiesta","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FVividCortex%2Fsiesta/lists"}