Documentation
¶
Overview ¶
Package httpkit is a batteries-included toolkit for HTTP services in Go.
The module is split into two packages that can be used independently:
- github.com/boostgo/httpkit/server builds an echo v4 server with a consistent JSON response envelope, trace ids, access logs with masking of sensitive values, body limits, panic recovery, pagination helpers, request parsing and validation, cookies and a response cache middleware.
- github.com/boostgo/httpkit/client is a thin, fluent HTTP client on top of net/http with a shared tuned connection pool, retry policies with backoff and Retry-After, per-call and per-attempt timeouts, response size limits, streaming JSON decoding, observers and body writers (JSON, multipart form-data, URL-encoded forms, raw bytes).
This root package only holds the bits shared by both, such as the ContentType* constants.
Index ¶
Constants ¶
View Source
const ( // ContentTypeText is the MIME type of plain text. ContentTypeText = "text/plain" // ContentTypeHTML is the MIME type of HTML documents. ContentTypeHTML = "text/html" // ContentTypeCSS is the MIME type of CSS stylesheets. ContentTypeCSS = "text/css" // ContentTypeJS is the MIME type of JavaScript sources. ContentTypeJS = "text/javascript" // ContentTypeCSV is the MIME type of CSV files. ContentTypeCSV = "text/csv" // ContentTypeGif is the MIME type of GIF images. ContentTypeGif = "image/gif" // ContentTypeIco is the MIME type of ICO icons. ContentTypeIco = "image/vnd.microsoft.icon" // ContentTypeJpeg is the MIME type of JPEG images. ContentTypeJpeg = "image/jpeg" // ContentTypePng is the MIME type of PNG images. ContentTypePng = "image/png" // ContentTypeSvg is the MIME type of SVG images. ContentTypeSvg = "image/svg+xml" // ContentTypeBmp is the MIME type of BMP images. ContentTypeBmp = "image/bmp" // ContentTypeMp3 is the MIME type of MP3 audio. ContentTypeMp3 = "audio/mpeg" // ContentTypeWav is the MIME type of WAV audio. ContentTypeWav = "audio/wav" // ContentTypeMp4 is the MIME type of MP4 video. ContentTypeMp4 = "video/mp4" // ContentTypeMpeg is the MIME type of MPEG video. ContentTypeMpeg = "video/mpeg" // ContentTypeBytes is the MIME type of arbitrary binary data. ContentTypeBytes = "application/octet-stream" // ContentTypeOctetStream is an alias of ContentTypeBytes. ContentTypeOctetStream = ContentTypeBytes // ContentTypeJSON is the MIME type of JSON documents. ContentTypeJSON = "application/json" // ContentTypeXML is the MIME type of XML documents. ContentTypeXML = "application/xml" // ContentTypeForm is the MIME type of URL-encoded forms. ContentTypeForm = "application/x-www-form-urlencoded" // ContentTypePdf is the MIME type of PDF documents. ContentTypePdf = "application/pdf" // ContentTypeRar is the MIME type of RAR archives. ContentTypeRar = "application/vnd.rar" // ContentTypeTar is the MIME type of TAR archives. ContentTypeTar = "application/x-tar" // ContentTypeZip is the MIME type of ZIP archives. ContentTypeZip = "application/zip" // ContentTypeSevenZip is the MIME type of 7z archives. ContentTypeSevenZip = "application/x-7z-compressed" // ContentTypeBash is the MIME type of shell scripts. ContentTypeBash = "application/x-sh" // ContentTypeJar is the MIME type of Java archives. ContentTypeJar = "application/java-archive" // ContentTypeWord is the MIME type of Microsoft Word (.docx) documents. ContentTypeWord = "application/vnd.openxmlformats-officedocument.wordprocessingml.document" // ContentTypeExcel is the MIME type of Microsoft Excel (.xlsx) spreadsheets. ContentTypeExcel = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet" // ContentTypePowerPoint is the MIME type of Microsoft PowerPoint (.pptx) presentations. ContentTypePowerPoint = "application/vnd.openxmlformats-officedocument.presentationml.presentation" // ContentTypeEpub is the MIME type of EPUB books. ContentTypeEpub = "application/epub+zip" // ContentTypeTtf is the MIME type of TrueType fonts. ContentTypeTtf = "font/ttf" )
MIME types shared by the server and client packages.
They are plain strings and can be used anywhere a Content-Type header value is expected, for example server.ReturnExcel uses ContentTypeExcel and client.Raw defaults to ContentTypeOctetStream.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
This section is empty.
Directories
¶
| Path | Synopsis |
|---|---|
|
Package client is a thin HTTP client on top of net/http with base url, shared headers/cookies/query params, middlewares and a retry mechanism.
|
Package client is a thin HTTP client on top of net/http with base url, shared headers/cookies/query params, middlewares and a retry mechanism. |
|
examples
|
|
|
client
command
Command client shows httpkit/client against a flaky local server: retries with backoff, per-attempt timeout, observers and typed results.
|
Command client shows httpkit/client against a flaky local server: retries with backoff, per-attempt timeout, observers and typed results. |
|
roundtrip
command
Command roundtrip starts an httpkit/server API in-process and consumes it with httpkit/client, decoding the response envelope.
|
Command roundtrip starts an httpkit/server API in-process and consumes it with httpkit/client, decoding the response envelope. |
|
server
command
Command server runs an echo server built with httpkit/server: response envelope, trace ids, access log, sentinel errors and pagination.
|
Command server runs an echo server built with httpkit/server: response envelope, trace ids, access log, sentinel errors and pagination. |
|
Package server builds echo v4 HTTP servers with a consistent JSON response envelope and production-ready defaults.
|
Package server builds echo v4 HTTP servers with a consistent JSON response envelope and production-ready defaults. |
Click to show internal directories.
Click to hide internal directories.