English | 中文
httpsrv is a lightweight, net/http-native Go web framework.
- net/http-native: the typical handler is
func(c Ctx) error, and a stdlibhttp.Handleris also accepted, so you can reuse the stdlib ecosystem and existing middleware directly. - Concise API: per-method route registration (
Get/Post/Put/...),All, nestableGroup,Usemiddleware, with chaining. - High-performance radix-tree routing: exact static segments,
{name}parameter segments; static routes take priority over parameter routes (independent of registration order). - Path parameters:
{name}segments are read viac.Params("name")(backed by the stdlibr.PathValue); no custom Context needed. - Few dependencies: stdlib only (plus
andybalholm/brotlifor compression andgolang.org/x/textfor locale matching); handlers can reuse the stdlib ecosystem and existing middleware directly.
- Quick Start
- Routing & Path Parameters
- Route Groups
- Middleware (Use)
- Running the Server (Run)
- Examples
- Static Files
- Ctx & Handler
- Template Rendering
- i18n
package main
import (
"github.com/hooto/httpsrv/v2"
)
func main() {
app := httpsrv.New()
app.Get("/", func(c httpsrv.Ctx) error {
return c.SendString("Hello, httpsrv!")
})
app.Run(":8080") // open http://localhost:8080/
}- Go 1.26+
- Run the tests:
go test ./...