versioning

package
v1.1.0-rc1 Latest Latest
Warning

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

Go to latest
Published: Jan 29, 2026 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrNotAcceptable = errors.New("requested API version not acceptable")

ErrNotAcceptable indicates the requested version is not supported for the endpoint.

Functions

func ContextWithVersion

func ContextWithVersion(ctx context.Context, v Version) context.Context

ContextWithVersion stores the negotiated version in context

func NewNegotiatedRouter

func NewNegotiatedRouter(
	negotiateMW Middleware,
	routers map[Version]chi.Router,
	fallback Version,
) (chi.Router, error)

NewNegotiatedRouter creates a router that negotiates the API version and dispatches to the appropriate version-specific router. It returns an error if the fallback version is empty or has no corresponding router.

func NewRouter

func NewRouter(cfg RouterConfig) chi.Router

NewRouter creates a chi router with version-specific middleware.

Types

type Middleware

type Middleware func(http.Handler) http.Handler

Middleware is an HTTP middleware function type.

type Negotiator

type Negotiator struct {
	// contains filtered or unexported fields
}

Negotiator provides version negotiation logic.

func NewNegotiator

func NewNegotiator(fallbackVersion Version) *Negotiator

NewNegotiator creates a negotiator with the specified fallback version.

func (*Negotiator) FallbackVersion

func (n *Negotiator) FallbackVersion() Version

FallbackVersion returns the fallback version.

func (*Negotiator) NegotiateMiddleware

func (n *Negotiator) NegotiateMiddleware(next http.Handler) http.Handler

NegotiateMiddleware is HTTP middleware that performs version negotiation.

type RouterConfig

type RouterConfig struct {
	Middlewares    []Middleware
	RegisterRoutes func(r chi.Router)
}

RouterConfig configures a version-specific router.

type Version

type Version string

Version represents an API version string

const (
	V1Beta1 Version = Version(apiversioning.V1Beta1)
)

func VersionFromContext

func VersionFromContext(ctx context.Context) (Version, bool)

VersionFromContext retrieves the negotiated version from context

func (Version) IsValid

func (v Version) IsValid() bool

IsValid returns true if the version string is a known version

Jump to

Keyboard shortcuts

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