apiversion

package module
v0.0.0-...-be21092 Latest Latest
Warning

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

Go to latest
Published: Feb 29, 2016 License: MIT Imports: 3 Imported by: 0

README

Build Status Coverage Status GoDoc Report Cart MIT License

Versioning API with Go

Simple API versioning with Go with or without any middleware stack.

# Installation

go get -v github.com/yageek/apiversion

How it works

Vendor identifier

Before tagging a version, an API is identified by a vendor identifier with the form application/vnd.mybusiness.com. If it matches the value of the Accept header, the handler will next try find a version that suits your needs.

Version

AS you can registered several versions for your API, if you don't specify one, the last registered will be selected by default.

To select, one particular version, the handler will match the version specified after within the Accept header after the vendor identifier.

For example, to match the v2 version, the request Accept header will be:

Accept: application/vnd.mybusiness.com-v2

Usage

The package works out of the box as a simple HTTP handler or can be integrated easily with any middleware stack.

For usage, see examples folder.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrVersionNotFound  = errors.New("Version not found")
	ErrVersionDuplicate = errors.New("Version with same identifer already present")
)

Common errors

Functions

This section is empty.

Types

type VendorMiddleware

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

VendorMiddleware dispatches the request regarding the wanted version.

func NewVendorMiddleware

func NewVendorMiddleware(name string, versions ...*Version) (*VendorMiddleware, error)

NewVendorMiddleware returns a new middleware.

func (*VendorMiddleware) CheckVendorHandler

func (v *VendorMiddleware) CheckVendorHandler(h http.Handler) http.Handler

CheckVendorHandler wraps an handler and call it only if the vendor corresponds to the appropriate vendor.

func (*VendorMiddleware) DispatchVersion

func (v *VendorMiddleware) DispatchVersion() http.Handler

DispatchVersion returns the handler that corresponds to the appropriate version.

func (*VendorMiddleware) ServeHTTP

func (v *VendorMiddleware) ServeHTTP(w http.ResponseWriter, r *http.Request)

Default implementation in case of non using a middleware

func (*VendorMiddleware) VendorName

func (v *VendorMiddleware) VendorName() string

VendorName returns the vendorName used to determine the vendor used in the "Accept" header.

type Version

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

Version represents an API version.

func NewVersion

func NewVersion(version string, handler http.Handler) *Version

NewVersion creates a new API with a specified name.

func (*Version) Version

func (a *Version) Version() string

Version returns the version of the API.

Directories

Path Synopsis
examples
raw

Jump to

Keyboard shortcuts

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