http

package
v0.0.0-...-fe14df0 Latest Latest
Warning

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

Go to latest
Published: Apr 30, 2019 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type JSON

type JSON map[string]interface{}

JSON is a short-cut for map[string]interface{}

type Request

type Request struct {
	Method    string
	URI       string
	Authority string // Host
	Scheme    string
	RawQuery  string
	Params    map[string]string
	Header    map[string]string
	Body      []byte
	// contains filtered or unexported fields
}

Request contains and manages all request-relevant data.

func NewRequest

func NewRequest() *Request

NewRequest builds a new request with initialized fields

func (*Request) Finish

func (r *Request) Finish()

Finish makes the request finished. Which means next handler in the function won't run.

func (*Request) IsFinished

func (r *Request) IsFinished() bool

IsFinished says if the request is finished or not

func (*Request) JSON

func (r *Request) JSON(target interface{})

JSON parses the request body as JSON into a target interface.

func (*Request) Param

func (r *Request) Param(name string) string

Param gets a value of a parameter by name

func (*Request) Query

func (r *Request) Query(name string) string

Query returns the value of a given query parameter

type Response

type Response struct {
	Status uint16
	Body   []byte
	Header map[string]string
	// contains filtered or unexported fields
}

Response represents a http-response

func NewResponse

func NewResponse(req *Request) *Response

NewResponse creates a new response

func (*Response) BadRequest

func (res *Response) BadRequest()

BadRequest sets response status-code to 403

func (*Response) Created

func (res *Response) Created()

Created sets response status-code to 201

func (*Response) File

func (res *Response) File(path string)

File reads and sets the file

func (*Response) Forbidden

func (res *Response) Forbidden()

Forbidden sets response status-code to 403

func (*Response) HTML

func (res *Response) HTML(path string, templateData interface{})

HTML reads an html-file and builds a html-response. Includes support for templates.

func (*Response) JSON

func (res *Response) JSON(status uint16, target interface{})

JSON sets body to the given content in json-format

func (*Response) NotFound

func (res *Response) NotFound()

NotFound sets response status-code to 404

func (*Response) Ok

func (res *Response) Ok()

Ok sets response status-code to 200

func (*Response) Push

func (res *Response) Push(path string)

Push performs a push server

func (*Response) PushRequests

func (res *Response) PushRequests() []*Request

PushRequests returns all initialized Push-Requests

func (*Response) String

func (res *Response) String(status uint16, s string)

String sets a string as response body.

func (*Response) Unauthorized

func (res *Response) Unauthorized()

Unauthorized sets response status-code to 401

Jump to

Keyboard shortcuts

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