doze

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

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

Go to latest
Published: Dec 13, 2018 License: MIT Imports: 11 Imported by: 2

README

Doze

Doze is a simple REST framework that allows you to quickly and efficiently create a RESTful api for your service

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ActionFunc

type ActionFunc func(*Context) ResponseSender

ActionFunc is a type that is a function to be used as a controller action

type BasicResponse

type BasicResponse struct {
	StatusCode int
	Headers    map[string]string
	Body       []byte
}

BasicResponse contains all basic properties for a response

func NewCreatedJSONResponse

func NewCreatedJSONResponse(body interface{}) BasicResponse

NewCreatedJSONResponse returns a BasicResponse tailored for JSON with status code of 201

func NewInternalServerErrorResponse

func NewInternalServerErrorResponse() BasicResponse

NewInternalServerErrorResponse returns a BasicResponse defaulted for an internal server error

func NewNoContentResponse

func NewNoContentResponse() BasicResponse

NewNoContentResponse returns a BasicResponse defaulted for no content

func NewNotFoundResponse

func NewNotFoundResponse() BasicResponse

NewNotFoundResponse returns a BasicResponse defaulted for not found

func NewOKJSONResponse

func NewOKJSONResponse(body interface{}) BasicResponse

NewOKJSONResponse returns a BasicResponse tailored for JSON with status code of 200

func (BasicResponse) Send

func (br BasicResponse) Send(w io.Writer) (int, error)

Send writes the BasicResponse body to the http.ResponseWriter

type Context

type Context struct {
	Request        *http.Request
	ResponseWriter *ResponseWriter
	Route          PatternedRoute
}

Context will contain all information about the current request scoped context

func (*Context) BindJSONEntity

func (c *Context) BindJSONEntity(i interface{}) error

BindJSONEntity binds the JSON body from the request to an interface{}

func (*Context) FormData

func (c *Context) FormData() url.Values

FormData returns data related to the request from GET, POST, or PUT

func (*Context) Set

func (c *Context) Set(key, value interface{})

Set puts a value on the current context.Context by key

func (*Context) Value

func (c *Context) Value(key interface{}) interface{}

Value returns the value by key on the current context.Context

type DozeRoute

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

func NewRoute

func NewRoute() *DozeRoute

NewRoute returns a new *DozeRoute

func (*DozeRoute) Actions

func (r *DozeRoute) Actions() map[string]ActionFunc

func (*DozeRoute) And

func (r *DozeRoute) And(method string, action ActionFunc) *DozeRoute

func (*DozeRoute) For

func (r *DozeRoute) For(path string) *DozeRoute

func (*DozeRoute) Name

func (r *DozeRoute) Name() string

func (*DozeRoute) Named

func (r *DozeRoute) Named(name string) *DozeRoute

func (*DozeRoute) ParamNames

func (r *DozeRoute) ParamNames() []string

func (*DozeRoute) ParamValues

func (r *DozeRoute) ParamValues() []interface{}

func (*DozeRoute) Path

func (r *DozeRoute) Path() string

func (*DozeRoute) SetActions

func (r *DozeRoute) SetActions(actions map[string]ActionFunc)

func (*DozeRoute) SetName

func (r *DozeRoute) SetName(name string)

func (*DozeRoute) SetParamNames

func (r *DozeRoute) SetParamNames(paramNames []string)

func (*DozeRoute) SetParamValues

func (r *DozeRoute) SetParamValues(paramValues []interface{})

func (*DozeRoute) SetPath

func (r *DozeRoute) SetPath(path string)

func (*DozeRoute) With

func (r *DozeRoute) With(method string, action ActionFunc) *DozeRoute

type GzipResponse

type GzipResponse struct {
	BasicResponse
}

GzipResponse is a wrapping response to gzip your BasicResponse

func NewGzipResponse

func NewGzipResponse(br BasicResponse) GzipResponse

NewGzipResponse creates a new GzipResponse that wraps a BasicResponse that adds Content-Encoding to gzip

func (GzipResponse) Send

func (gr GzipResponse) Send(w io.Writer) (int, error)

Send creates a gzip writer and writes to the http.ResponseWriter

type Handler

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

Handler implements http.Handler and contains the router and controllers for the REST api

func NewHandler

func NewHandler(r Routeable) *Handler

NewHandler returns a new Handler with router initialized

func (*Handler) ServeHTTP

func (h *Handler) ServeHTTP(w http.ResponseWriter, r *http.Request)

func (*Handler) Use

func (h *Handler) Use(mf MiddlewareFunc)

Use applies a MiddlewareFunc to be executed in the request chain

type MiddlewareFunc

type MiddlewareFunc func(*Context, NextFunc)

MiddlewareFunc is a function type for adding middleware to the request

type NextFunc

type NextFunc func(*Context)

NextFunc is a function type that progresses the middleware chain for the request

type PatternedRoute

type PatternedRoute struct {
	Route
}

func (PatternedRoute) Build

func (r PatternedRoute) Build(m map[string]interface{}) (string, error)

Build returns the route path with route parameters replaced with values from the passed in map

func (PatternedRoute) Params

func (r PatternedRoute) Params() map[string]interface{}

Params returns a key-value pair containing the route parameters defined in the route path. ParamNames should alwyas go 1-1 to the ParamValues, otherwise you will have a bad time

type ResponseSender

type ResponseSender interface {
	Send(w io.Writer) (int, error)
}

ResponseSender is an interface to send response from ControllerActions

type ResponseWriter

type ResponseWriter struct {
	http.ResponseWriter
	Size       int
	StatusCode int
}

ResponseWriter is a wrapper for http.ResponseWriter which includes extra properties to keep track of current response

func (*ResponseWriter) Write

func (rw *ResponseWriter) Write(b []byte) (int, error)

func (*ResponseWriter) WriteHeader

func (rw *ResponseWriter) WriteHeader(i int)

WriteHeader is overidding http.ResponseWriter in order to capture the StatusCode of the request

func (*ResponseWriter) Written

func (rw *ResponseWriter) Written() bool

Written returns whether or not the current response has been written to

type RestRouter

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

func Router

func Router(name string) RestRouter

NewRouter returns a router specified by a name

func (RestRouter) Add

func (ro RestRouter) Add(route Route)

func (RestRouter) Get

func (ro RestRouter) Get(name string) PatternedRoute

func (RestRouter) Match

func (ro RestRouter) Match(test string) (PatternedRoute, bool)

func (RestRouter) Prefix

func (ro RestRouter) Prefix() string

func (RestRouter) SetPrefix

func (ro RestRouter) SetPrefix(prefix string) RestRouter

type Route

type Route interface {
	Name() string
	Path() string
	Actions() map[string]ActionFunc
	ParamNames() []string
	ParamValues() []interface{}

	SetName(string)
	SetPath(string)
	SetActions(map[string]ActionFunc)
	SetParamNames([]string)
	SetParamValues([]interface{})
}

type Routeable

type Routeable interface {
	Get(string) PatternedRoute
	Match(string) (PatternedRoute, bool)
}

Routeable is an interface which allows you to create your own router

  • Get(string) *Route returns the route by route name
  • Match(string) *Route takes a URI and returns a *Route it matches. If it does not it returns nil

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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