web

package
v0.3.4 Latest Latest
Warning

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

Go to latest
Published: Aug 10, 2016 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const (
	GET    string = "GET"
	POST   string = "POST"
	PUT    string = "PUT"
	DELETE string = "DELETE"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type AppContext

type AppContext struct {
	Writer http.ResponseWriter
	Header http.Header
	Body   io.ReadCloser
	Vars   map[string]string
	MDB    *db.MongoDB
	RMQ    *amqp.MQ
	SD     *statsd.SD
	Event  string
}

AppContext encapsulates application specific runtime information

func NewContext

func NewContext(rw http.ResponseWriter, r *http.Request) *AppContext

func (*AppContext) Clone

func (c *AppContext) Clone() *AppContext

Returns a cloned context with db and mq resources A cloned context must not be closed

func (*AppContext) Close

func (c *AppContext) Close()

func (*AppContext) GetValue

func (c *AppContext) GetValue(key string) string

func (*AppContext) Marshall

func (c *AppContext) Marshall(j interface{})

Marshall marshalls an incoming object and sets it to the Body

func (*AppContext) SetValue

func (c *AppContext) SetValue(k string, v string) string

func (*AppContext) Unmarshall

func (c *AppContext) Unmarshall(input interface{}) error

Unmarshall unmarshalls the Body to the passed object

type AppError

type AppError struct {
	Error   error  `json:"error,omitempty"`
	Message string `json:"message,omitempty"`
	Code    int    `json:"code,omitempty"`
}

AppError encapsulates application specific error

type HandlerFunc

type HandlerFunc func(c *AppContext)

overwrites the handlerfunc

func (HandlerFunc) ServeHTTP

func (h HandlerFunc) ServeHTTP(rw http.ResponseWriter, r *http.Request)

type Response

type Response struct {
	Status     string
	Header     http.Header
	Body       string
	StatusCode int
}

Response encapsulates a http response

func Request

func Request(method string, url string, header map[string]string, payload io.Reader) (*Response, error)

Request is a common method for a REST call, returns a Response

Jump to

Keyboard shortcuts

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