Documentation ¶
Index ¶
- type Extender
- type GhostError
- type HttpError
- type NullModel
- type NullProcessor
- type NullValidator
- type NullWriter
- type Processor
- type RequestModel
- type RouteBuilder
- func (b *RouteBuilder) Extender(e Extender) *RouteBuilder
- func (b *RouteBuilder) Methods(methods ...string) *RouteBuilder
- func (b *RouteBuilder) Model(m RequestModel) *RouteBuilder
- func (b *RouteBuilder) Processor(p Processor) *RouteBuilder
- func (b *RouteBuilder) ServeHTTP(w http.ResponseWriter, r *http.Request)
- func (b *RouteBuilder) Validator(v Validator) *RouteBuilder
- func (b *RouteBuilder) Writer(w Writer) *RouteBuilder
- type Router
- type Validator
- type Writer
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Extender ¶
type Extender interface { // Extend the context by calling ctx.WithValue() Extend(ctx context.Context) context.Context }
A context extender is an interface that adds values to a context that passes through it. For example, if you want database access inside a context you might build a context extender to pass along database connections.
type GhostError ¶
type GhostError struct {
// contains filtered or unexported fields
}
An implementation of HttpError for simple things.
func (*GhostError) Error ¶
func (e *GhostError) Error() string
func (*GhostError) StatusCode ¶
func (e *GhostError) StatusCode() int
type HttpError ¶
A type for HTTP errors that extend the base error type. Provides a method for status codes to return to the HTTP client.
func NewHttpError ¶
type NullProcessor ¶
type NullProcessor struct { }
A null processor doesn't do anything
func (*NullProcessor) Process ¶
func (p *NullProcessor) Process(interface{}) (interface{}, HttpError)
type NullValidator ¶
type NullValidator struct { }
A null validator doesn't do anything
func (*NullValidator) Validate ¶
func (v *NullValidator) Validate(interface{}) HttpError
type NullWriter ¶
type NullWriter struct { }
A null writer doesn't do anything
func (*NullWriter) Serialize ¶
func (w *NullWriter) Serialize(interface{}) ([]byte, HttpError)
type Processor ¶
type Processor interface { // Process the information or return an HTTP error if something is wrong, // or nil otherwise. Process(source interface{}) (interface{}, HttpError) }
type RequestModel ¶
type RequestModel interface { // Fill the model with the information from the request. One way to do this // is to just use json.Unmarshal(), but you might also want some other // information extracted. FromRequest(r *http.Request) HttpError }
A request model is a type that wraps user input from a request body. Typically this will be a struct representation of some JSON object.
type RouteBuilder ¶
type RouteBuilder struct {
// contains filtered or unexported fields
}
func (*RouteBuilder) Extender ¶
func (b *RouteBuilder) Extender(e Extender) *RouteBuilder
Add an Extender that extends the request context coming through to the HTTP handler.
func (*RouteBuilder) Methods ¶
func (b *RouteBuilder) Methods(methods ...string) *RouteBuilder
Define the HTTP methods (verbs) that can be used on this route.
func (*RouteBuilder) Model ¶
func (b *RouteBuilder) Model(m RequestModel) *RouteBuilder
Add a model which is simply a representation of the client input in a Go data structure.
func (*RouteBuilder) Processor ¶
func (b *RouteBuilder) Processor(p Processor) *RouteBuilder
A processor operates on the input sent from the client, manipulates, extends it, whatever. Ultimately it returns something new.
func (*RouteBuilder) ServeHTTP ¶
func (b *RouteBuilder) ServeHTTP(w http.ResponseWriter, r *http.Request)
Satisfies the http.Handler interface. The route builder will use the provided extensions to create a handler and serve HTTP through the given extensions.
func (*RouteBuilder) Validator ¶
func (b *RouteBuilder) Validator(v Validator) *RouteBuilder
Add a validator, which validates input coming from the HTTP client before it gets operated on by a processor or writer.
func (*RouteBuilder) Writer ¶
func (b *RouteBuilder) Writer(w Writer) *RouteBuilder
Add a writer which serializes the output from a processor.
type Router ¶
A ghost router is actually backed by a gorilla mux, but we add some helpers to make building the API a little easier.
func (*Router) AddRoute ¶
func (r *Router) AddRoute(path string) *RouteBuilder
Add the given path to the router, and return a route builder to begin constructing the additional properties of the router.