go get -u github.com/lrstanley/chix/v2@latesthttp.Serverhelpers (Run,RunTLS) for starting and gracefully shutting down the server, with optional background jobs alongside HTTP vialrstanley/x/sync/scheduler.- Per-request
Configmiddleware: API base path, JSON encode/decode hooks, request decode/validate,slog.Logger, error resolvers, and masking of non-public 5xx errors. - RealIP middleware (trusted proxy chain parsing; not "trust any
X-Forwarded-For"). - Private IP middleware for internal-only routes.
- Request ID middleware (client header or generated ID; header name configurable on
Config). - Rendering helpers: JSON, XML, CSV, and streaming CSV via iterators -- all support
?pretty=truewhere applicable. JSON uses the standard library by default;encoding/json/v2automatically used when compiled with support for it. - Optional subpackage
xmetrics: Prometheus HTTP request metrics (duration, count, bytes) keyed by chi route pattern. - Auth (
xauthsubpackage):- markbates/goth OAuth with many providers, plus a separate basic-auth flow.
- Cookie-backed sessions (gorilla/sessions); encrypted store helpers so you can avoid server-side session storage.
- Generics for user identity type and ID -- no hand-rolled type assertions for your models.
- Optional auth context, required-auth middleware, and
OverrideContextAuthfor tests or impersonation.
- API key and API version validation middleware (configurable headers).
- Struct binding from query, form, JSON, and multipart data with go-playground/validator.
- Structured request logging with
log/slog:UseStructuredLoggerwith configurable schemas, levels, optional request/response body capture, panic recovery, andAppendLogAttrs/Log(and level helpers) for handler-local fields. - Debug middleware so handlers can tell if debug mode is on; integrates with error responses when you want details only in debug.
- Error handling that distinguishes API vs static/HTML responses, with
ResolvedError, optionalExposableError, and per-error-type resolver functions. go:embedstatic file serving (SPA fallback, optional local directory override for development, catch-all safe behavior near API routes).- Redirect helpers for auth flows: store a
nextURL in a cookie and redirect safely afterward. - Small utilities: multi-header middleware, strip-slashes that skips
/debug/for pprof, conditional middleware (UseIf/UseIfFunc). - Middleware for
robots.txtandsecurity.txt.
- lrstanley/clix -- go-flags wrapper, that handles parsing and decoding, with additional helpers.
- lrstanley/go-query-parser -- similar to that of Google/Github/etc search, a query string parser that allows filters and tags to be dynamically configured by the end user.
Use these as a reference point for how you might use some of the functionality within this library, or how you might want to structure your applications.
- β€οΈ Please review the Code of Conduct for guidelines on ensuring everyone has the best experience interacting with the community.
- πββοΈ Take a look at the support document on guidelines for tips on how to ask the right questions.
- π For all features/bugs/issues/questions/etc, head over here.
- β€οΈ Please review the Code of Conduct for guidelines on ensuring everyone has the best experience interacting with the community.
- π Please review the contributing doc for submitting issues/a guide on submitting pull requests and helping out.
- ποΈ For anything security related, please review this repositories security policy.
MIT License
Copyright (c) 2022 Liam Stanley <liam@liam.sh>
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
Also located here