Documentation
¶
Index ¶
- Variables
- func ContextWithVersion(ctx context.Context, v Version) context.Context
- func NewNegotiatedRouter(negotiateMW Middleware, routers map[Version]chi.Router, fallback Version) (chi.Router, error)
- func NewRouter(cfg RouterConfig) chi.Router
- type Middleware
- type Negotiator
- type RouterConfig
- type Version
Constants ¶
This section is empty.
Variables ¶
var ErrNotAcceptable = errors.New("requested API version not acceptable")
ErrNotAcceptable indicates the requested version is not supported for the endpoint.
Functions ¶
func ContextWithVersion ¶
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 ¶
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 ¶
VersionFromContext retrieves the negotiated version from context