middleware

package module
v0.32.2 Latest Latest
Warning

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

Go to latest
Published: May 27, 2026 License: Apache-2.0 Imports: 0 Imported by: 0

README

server-middleware

GoDoc

Standalone, dependency-free server-side middleware utilities for OpenAPI applications.

This module is part of the go-openapi/runtime toolkit, but is maintained as a separate Go module so it can be used by any net/http application — including ones that have no OpenAPI spec at all. It carries no transitive dependency on go-openapi/spec, go-openapi/loads, or go-openapi/validate; only the standard library and (for tests) go-openapi/testify/v2.

Packages

Package Purpose
mediatype Typed RFC 7231 / RFC 2045 media-type values (MediaType, Set) and asymmetric matching used by both server-side validation and Accept-header negotiation.
negotiate Server-side HTTP content negotiation: select the response Content-Type from Accept, and the response Content-Encoding from Accept-Encoding. Honours MIME parameters by default; opt out with WithIgnoreParameters.
negotiate/header Low-level RFC-7231 header parsing primitives reused by negotiate. Exported for callers that need raw Accept/Accept-Encoding parsing without the typed media-type layer.
docui Stdlib-only HTTP middlewares that serve OpenAPI documentation UIs (Swagger UI, ReDoc, RapiDoc) and the spec document itself. Mountable on any net/http mux.

Install

go get github.com/go-openapi/runtime/server-middleware

Quick start — content negotiation

import "github.com/go-openapi/runtime/server-middleware/negotiate"

offers := []string{"application/json", "application/xml"}
chosen := negotiate.ContentType(r.Header, offers, "application/json")
w.Header().Set("Content-Type", chosen)

Quick start — serving Swagger UI

import "github.com/go-openapi/runtime/server-middleware/docui"

handler := docui.SwaggerUI(docui.WithSpecURL("/swagger.json"), docui.WithBasePath("/docs"))
http.Handle("/docs/", handler)

Further reading

License

Apache-2.0.

Documentation

Overview

Package middleware exposes middleware utilities for OpenAPI.

This is a standalone module, with minimal dependencies to the rest of the go-openapi libraries.

Directories

Path Synopsis
Package docui provides standalone HTTP middlewares that serve OpenAPI documentation UIs (Swagger UI, ReDoc, RapiDoc) and the spec document itself.
Package docui provides standalone HTTP middlewares that serve OpenAPI documentation UIs (Swagger UI, ReDoc, RapiDoc) and the spec document itself.
Package mediatype provides a typed value for media types defined by RFC 7231 and RFC 2045.
Package mediatype provides a typed value for media types defined by RFC 7231 and RFC 2045.
Package negotiate provides server-side HTTP content negotiation helpers — selecting the response Content-Type from an Accept header and the response Content-Encoding from an Accept-Encoding header.
Package negotiate provides server-side HTTP content negotiation helpers — selecting the response Content-Type from an Accept header and the response Content-Encoding from an Accept-Encoding header.
header
Package header provides functions for parsing HTTP headers.
Package header provides functions for parsing HTTP headers.

Jump to

Keyboard shortcuts

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