Skip to content

lrstanley/chix

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

278 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

logo

πŸ”— Table of Contents

βš™οΈ Usage

go get -u github.com/lrstanley/chix/v2@latest

✨ Features

  • http.Server helpers (Run, RunTLS) for starting and gracefully shutting down the server, with optional background jobs alongside HTTP via lrstanley/x/sync/scheduler.
  • Per-request Config middleware: 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=true where applicable. JSON uses the standard library by default; encoding/json/v2 automatically used when compiled with support for it.
  • Optional subpackage xmetrics: Prometheus HTTP request metrics (duration, count, bytes) keyed by chi route pattern.
  • Auth (xauth subpackage):
    • 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 OverrideContextAuth for 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: UseStructuredLogger with configurable schemas, levels, optional request/response body capture, panic recovery, and AppendLogAttrs / 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, optional ExposableError, and per-error-type resolver functions.
  • go:embed static file serving (SPA fallback, optional local directory override for development, catch-all safe behavior near API routes).
  • Redirect helpers for auth flows: store a next URL 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.txt and security.txt.

⚑ Related Libraries

  • 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.

πŸ’‘ Example Projects

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.

πŸ™‹β€β™‚οΈ Support & Assistance

  • ❀️ 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.

🀝 Contributing

  • ❀️ 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.

βš–οΈ License

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

About

helper middleware and functionality for go-chi/chi

Topics

Resources

License

Code of conduct

Contributing

Security policy

Stars

Watchers

Forks

Sponsor this project

 

Contributors