Welcome to the world of httpok, your Go library for extending the capabilities of the standard net/http package!
To get httpok, you can use go get:
go get github.com/candango/httpok
httpok uses the standard library *slog.Logger directly. The log backend is
selected by the application through a slog.Handler:
textLogger := slog.New(slog.NewTextHandler(os.Stderr, nil))
jsonLogger := slog.New(slog.NewJSONHandler(os.Stderr, nil))
store := session.NewMemoryStore()
engine := session.NewStoreEngine(store, session.WithLogger(textLogger))
handler := middleware.Chain(
http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {}),
middleware.Logging(textLogger),
middleware.Sessioned(engine),
)
server := httpok.NewGracefulServer(
&http.Server{Handler: handler},
"example",
).WithLogger(textLogger)
if err := server.Run(); err != nil {
textLogger.Error("server stopped", "err", err)
}Use a text handler during development and a JSON handler in production. A nil
logger or an omitted logger uses the current slog.Default() when a record is
emitted, so a later slog.SetDefault is honored.
The v0.4.0 logging migration is breaking: the legacy logger.Logger,
logger.StandardLogger, and logger package were removed. Update server,
middleware, and session configuration to pass *slog.Logger instead. Run
blocks until shutdown and returns lifecycle errors; clean signal shutdown
returns nil. The legacy access-log timestamp uses a 24-hour clock and
numeric timezone offset: [02/01/2006:15:04:05 -0700].
HttpOK is one of Candango Open Source Group initiatives. Available under the MIT License.
This site and all documentation are licensed under Creative Commons 3.0.
Copyright © 2024-2026 Flavio Garcia