Overview
A small chi-backed HTTP server, router, middleware, params, JSON helpers, and Server-Sent Events.
http/server is the server half of github.com/toaweme/http. It wraps net/http.Server behind a chi-backed Router and a Name, Start, Stop lifecycle, and bundles the middleware, path params, JSON helpers, and Server-Sent Events you reach for on every service. chi stays an implementation detail, so handlers keep plain net/http signatures and never import it.
Install
go get github.com/toaweme/http/serverMount a router and serve JSON
Build a Router, register a handler with a method helper, then wrap it in a Server and start it. Handlers use the standard http.ResponseWriter and *http.Request, and reach for WriteJSON to send a response.
package main
import (
"net/http"
"github.com/toaweme/http/server"
"github.com/toaweme/log"
)
func main() {
logger := log.New()
r := server.NewRouter()
r.Get("/health", func(w http.ResponseWriter, _ *http.Request) {
server.WriteJSON(w, http.StatusOK, map[string]string{"status": "ok"})
})
srv := server.NewServer(server.Config{Host: "127.0.0.1", Port: 8080}, r, logger)
if err := srv.Start(); err != nil {
log.Fatal("http server failed", "error", err)
}
}Start blocks and serves until Stop(ctx) shuts it down gracefully. The Logger argument is satisfied structurally by github.com/toaweme/log, so you can inject that directly or a null logger to discard output.
Note
The module depends only on go-chi/chi. The Server-Sent Events helpers live in the server/sse sub-package, imported as sse.
Where to go next
Start with the guides to learn how each piece behaves, then reach for the reference when you need the exact signature.
Server, tune the transport with options, and shut down gracefully.JSON responsesRead request bodies and write JSON results and errors.Reading paramsPull path parameters, wildcards, and the matched route pattern without touching chi.Auth middlewareExtract a Bearer token into request context and read the caller's identity in handlers.Server-Sent EventsStream events to clients over SSE and fan out to subscribers with a topic hub.ReferenceThe router, server, JSON helpers, params, middleware, and the SSE package.