httpservice

package
v1.0.1-0...-8e9dff6 Latest Latest
Warning

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

Go to latest
Published: Dec 4, 2018 License: MIT Imports: 14 Imported by: 2

Documentation

Index

Constants

View Source
const (
	MWOuter    = -10
	MWProtocol = -5
	MWPrepare  = -1
	MWNormal   = 0
	MWInner    = 10
)
  • MWNormal is reserved for any

weight of different middlewares

MWOuter is for middleware that runs before any protocol read or / and after any protocol output

MWProtocol is for middleware that unwrap decoded request from a protocol or wraps the results in a proper line protocol before encode

MWPrepare is for middleware to prepare the request before endpoint or prepare the response before protocol

MWNormal is reserved for any

MWInner is for middleware to run between normal middleware and the endpoint

Variables

This section is empty.

Functions

func EnforceCreate

func EnforceCreate(payload interface{}) (err error)

EnforceCreate enforce some field on creation, as defined in struct field tags

func EnforceUpdate

func EnforceUpdate(original, update interface{}) (err error)

EnforceUpdate enforce some fields value on update, as defined in struct field tags

func ProvideJSONDecoder

func ProvideJSONDecoder(parent context.Context, r *http.Request) context.Context

ProvideJSONDecoder provides JSON encoder with a given *http.Request to context

func WithDecoder

func WithDecoder(parent context.Context, provider DecoderProvider) context.Context

WithDecoder adds a decoder to context so you can latter retrieve with DecoderFrom(context)

func WithPartialDecoder

func WithPartialDecoder(parent context.Context, provider DecoderProvider) context.Context

WithPartialDecoder adds a decoder to context so you can latter retrieve with DecoderFrom(context)

Types

type Decoder

type Decoder interface {
	Decode(v interface{}) (err error)
}

Decoder decodes streams it receives to the pointer v provided

func DecoderFrom

func DecoderFrom(ctx context.Context) (dec Decoder, ok bool)

DecoderFrom gets decoder set to the context

func PartialDecoderFrom

func PartialDecoderFrom(ctx context.Context) (dec Decoder, ok bool)

PartialDecoderFrom gets decoder set to the context

type DecoderProvider

type DecoderProvider func(r *http.Request) Decoder

DecoderProvider provides decoder

type Desc

type Desc interface {
	Paths() Paths
	SetMiddleware(name string, mware endpoint.Middleware)
	GetMiddleware(name string) endpoint.Middleware
	SetDecodeFunc(name string, dec httptransport.DecodeRequestFunc)
	GetDecodeFunc(name string) httptransport.DecodeRequestFunc
}

Desc is the descriptor of a RESTful service

func NewDesc

func NewDesc(paths Paths) Desc

NewDesc returns the default implementation of Desc

type MWCond

type MWCond func(mw Middleware) bool

MWCond is the condition for removing middleware in a set

func WeightIs

func WeightIs(weight int) MWCond

WeightIs returns MWCond that matches middleware by weight

type Middleware

type Middleware struct {
	endpoint.Middleware
	Weight int
}

Middleware wrap a middleware with a weight parameter

type Middlewares

type Middlewares []Middleware

Middlewares contain middlewares to use in the service

func (*Middlewares) Add

func (wares *Middlewares) Add(weight int, waresToAdd ...endpoint.Middleware)

Add appends a middleware to the set

func (Middlewares) Chain

func (wares Middlewares) Chain() endpoint.Middleware

Chain is the helper function for composing middlewares in specific order

func (Middlewares) Len

func (wares Middlewares) Len() int

Len implements sort.Interface

func (Middlewares) Less

func (wares Middlewares) Less(i, j int) bool

Less implements sort.Interface

func (*Middlewares) Remove

func (wares *Middlewares) Remove(cond MWCond)

Remove removes a middleware by condition

func (Middlewares) Slice

func (wares Middlewares) Slice() (slice []endpoint.Middleware)

Slice returns a sorted []endpoint.Middleware

func (Middlewares) Swap

func (wares Middlewares) Swap(i, j int)

Swap implements sort.Interface

type Noun

type Noun interface {
	Singular() string
	Plural() string
}

Noun contains and return the singular and plural variant of a noun

func NewNoun

func NewNoun(singular, plural string) Noun

NewNoun creates a Noun interface containing given info

type Paths

type Paths interface {
	Base() string
	Noun() Noun
	Singular() string
	Plural() string
}

Paths return the URL base and the RESTful service noun

func NewPaths

func NewPaths(base string, noun Noun, idStr string) Paths

NewPaths return the default Paths implementation with given information

type Request

type Request struct {

	// Request stores the raw *http.Request
	Request *http.Request

	// Query stores the parsed Query information
	Query store.Query

	// Previous stores, if any, previous entity information (mainly for update)
	Previous interface{}

	// Payload stores, if any, current request payload information
	Payload interface{}
}

Request contains all common fields needed for a usual API request

type RouterFunc

type RouterFunc func(path string, methods []string, h http.Handler) error

RouterFunc generalize router to route an http.Handler

type Service

type Service struct {
	Path        string
	Methods     []string
	Weight      int
	Context     context.Context
	Middlewares *Middlewares
	Endpoint    endpoint.Endpoint
	DecodeFunc  httptransport.DecodeRequestFunc
	EncodeFunc  httptransport.EncodeResponseFunc

	Before       []httptransport.RequestFunc
	After        []httptransport.ServerResponseFunc
	ErrorEncoder httptransport.ErrorEncoder
	Options      []httptransport.ServerOption
}

Service contains all parameters needed to call httptransport.NewServer

func NewJSONService

func NewJSONService(path string, ep endpoint.Endpoint) *Service

NewJSONService creates a service descriptor with defaults for a simple JSON service

func (Service) Handler

func (s Service) Handler() http.Handler

Handler returns go-kit http transport server of the given definition

func (Service) Route

func (s Service) Route(rtr RouterFunc) error

Route add the given service to router with RouterFunc

type ServiceSlice

type ServiceSlice []*Service

ServiceSlice attaches the method of sort.Interface to []*Service, sort in increasing order

func (ServiceSlice) Len

func (ss ServiceSlice) Len() int

Len implements sort.Interface

func (ServiceSlice) Less

func (ss ServiceSlice) Less(i, j int) bool

Less implements sort.Interface

func (ServiceSlice) Sort

func (ss ServiceSlice) Sort()

Sort is a short hand for sort.Sort(ServiceSlice)

func (ServiceSlice) Swap

func (ss ServiceSlice) Swap(i, j int)

Swap implements sort.Interface

type Services

type Services map[string]*Service

Services contain a group of named services

func (Services) Each

func (services Services) Each() <-chan *Service

Each returns a channel that return services by weight order

func (Services) Patch

func (services Services) Patch(patches ...ServicesPatch)

Patch takes a patch / patches and apply them to the group

func (Services) Route

func (services Services) Route(rtr RouterFunc) (err error)

Route routes all services in the group

type ServicesPatch

type ServicesPatch func(Services) Services

ServicesPatch patches all children in a map[string]*Service

Jump to

Keyboard shortcuts

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