go-httpkit

module
v0.1.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 13, 2026 License: MIT

README

go-httpkit

Simple HTTP utilities for Go projects (chi, JSON, validation, errors, metrics).

Install

go get github.com/TakuyaYagam1/go-httpkit

Packages

  • httperr — Typed HTTP errors with status and code, Unwrap(), sentinels (ErrInvalidID, ErrNotAuthenticated), NewValidationErrorf.
  • httputil — JSON render (RenderOK, RenderCreated, RenderError, …), HandleError (map httperr to JSON), request decode/validate (DecodeAndValidate, DecodeJSON with size limit and no trailing data), UUID params (ParseUUID, ParseAuthUserID), GetClientIP (trusted proxies), multipart limit, download helpers (RenderJSONAttachment, RenderStream, RenderBytes), search (EscapeILIKE, ValidateSearchQ), pagination (ClampPage, ParseIntQuery, Ptr).
  • httputil/middleware — Prometheus metrics (http_requests_total, http_request_duration_seconds); path from request via PathFromRequest (e.g. chi route pattern).

Requires go-chi/render and go-playground/validator in your app for full use. Validator interface: Validate(any) error.

Directories

Path Synopsis
Package httperr provides HTTP-aware error types for use with JSON APIs.
Package httperr provides HTTP-aware error types for use with JSON APIs.
Package httputil provides HTTP helpers: error handling and JSON responses, request decoding and validation, pagination (ClampPage, ClampPerPage, ParseIntQuery), client IP resolution with proxy headers, search sanitization (EscapeILIKE), multipart limits, file download responses, and chi route pattern extraction (ChiPathFromRequest).
Package httputil provides HTTP helpers: error handling and JSON responses, request decoding and validation, pagination (ClampPage, ClampPerPage, ParseIntQuery), client IP resolution with proxy headers, search sanitization (EscapeILIKE), multipart limits, file download responses, and chi route pattern extraction (ChiPathFromRequest).
middleware
Package middleware provides HTTP middleware for go-httpkit.
Package middleware provides HTTP middleware for go-httpkit.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL