ext

package
v0.0.0-...-712f093 Latest Latest
Warning

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

Go to latest
Published: Aug 11, 2015 License: GPL-2.0 Imports: 14 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ResolveCallback

func ResolveCallback(req *http.Request) string

func ResolveContentType

func ResolveContentType(req *http.Request) string

Get the content type. e.g. From "multipart/form-data; boundary=--" to "multipart/form-data" If none is specified, returns "text/html" by default.

func ResolveFormat

func ResolveFormat(req *http.Request) string

ResolveFormat maps the request's Accept MIME type declaration to a Request.Format attribute, specifically "html", "xml", "json", or "txt", returning a default of "html" when Accept header cannot be mapped to a value above.

func ResolvePrint

func ResolvePrint(req *http.Request) bool

func Serve

func Serve(listener net.Listener, handler http.Handler, proto_name string, logger log.Logger)

Types

type AcceptLanguage

type AcceptLanguage struct {
	Language string
	Quality  float32
}

AcceptLanguage is a single language from the Accept-Language HTTP header.

type AcceptLanguages

type AcceptLanguages []AcceptLanguage

AcceptLanguages is collection of sortable AcceptLanguage instances.

func ResolveAcceptLanguage

func ResolveAcceptLanguage(req *http.Request) AcceptLanguages

ResolveAcceptLanguage returns a sorted list of Accept-Language header values.

The results are sorted using the quality defined in the header for each language range with the most qualified language range as the first element in the slice.

See the HTTP header fields specification (http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.4) for more details.

func (AcceptLanguages) Len

func (al AcceptLanguages) Len() int

func (AcceptLanguages) Less

func (al AcceptLanguages) Less(i, j int) bool

func (AcceptLanguages) String

func (al AcceptLanguages) String() string

func (AcceptLanguages) Swap

func (al AcceptLanguages) Swap(i, j int)

type BinaryResult

type BinaryResult struct {
	Reader   io.Reader
	Name     string
	Length   int64
	Delivery ContentDisposition
	ModTime  time.Time
}

func (BinaryResult) Apply

func (r BinaryResult) Apply(req *Request, resp *Response)

type ContentDisposition

type ContentDisposition string
var (
	Attachment ContentDisposition = "attachment"
	Inline     ContentDisposition = "inline"
)

type Controller

type Controller struct {
	Request  *Request
	Response *Response
}

func NewController

func NewController(request *Request, response *Response) *Controller

func (*Controller) Binary

func (r *Controller) Binary(name string, rd io.Reader, size int64)

func (*Controller) File

func (r *Controller) File(path string)

func (*Controller) Html

func (r *Controller) Html(html string)

func (*Controller) Json

func (r *Controller) Json(data interface{})

func (*Controller) JsonError

func (r *Controller) JsonError(status int, err error)

func (*Controller) Read

func (r *Controller) Read(content_type string, rd io.Reader, sz int64)

func (*Controller) Redirect

func (r *Controller) Redirect(uri string, query string)

func (*Controller) Template

func (r *Controller) Template(t template.Template, data interface{})

func (*Controller) Text

func (r *Controller) Text(text string)

func (*Controller) TextError

func (r *Controller) TextError(status int, err error)

func (*Controller) Xml

func (r *Controller) Xml(data interface{})

type HtmlResult

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

func (HtmlResult) Apply

func (r HtmlResult) Apply(req *Request, resp *Response)

type JsonErrorResult

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

func (JsonErrorResult) Apply

func (r JsonErrorResult) Apply(req *Request, resp *Response)

type JsonResult

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

func (JsonResult) Apply

func (r JsonResult) Apply(req *Request, resp *Response)

type ReaderResult

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

func (ReaderResult) Apply

func (r ReaderResult) Apply(req *Request, resp *Response)

type RedirectResult

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

func (RedirectResult) Apply

func (r RedirectResult) Apply(req *Request, resp *Response)

type Request

type Request struct {
	*http.Request
	ContentType     string
	Format          string // "html", "xml", "json", or "txt"
	Pretty          bool
	Callback        string
	AcceptLanguages AcceptLanguages
	Locale          string
	ResultErr       error
}

func NewRequest

func NewRequest(r *http.Request) *Request

func (*Request) Data

func (r *Request) Data() io.ReadCloser

func (*Request) JsonData

func (r *Request) JsonData(data interface{}) error

func (*Request) MethodToLower

func (r *Request) MethodToLower() string

func (*Request) Param

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

func (*Request) Params

func (r *Request) Params(name string) []string

func (*Request) Suffix

func (r *Request) Suffix() string

func (*Request) TrimSuffixURI

func (r *Request) TrimSuffixURI(suffix string) string

func (*Request) URI

func (r *Request) URI() string

type Response

type Response struct {
	Status      int
	ContentType string
	Out         http.ResponseWriter
}

func NewResponse

func NewResponse(w http.ResponseWriter) *Response

func (*Response) SetCookie

func (resp *Response) SetCookie(cookie *http.Cookie)

func (*Response) WriteHeader

func (resp *Response) WriteHeader(defaultStatusCode int, defaultContentType string)

Write the header (for now, just the status code). The status may be set directly by the application (c.Response.Status = 501). if it isn't, then fall back to the provided status code.

type Result

type Result interface {
	Apply(req *Request, resp *Response)
}

type TemplateResult

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

func (TemplateResult) Apply

func (r TemplateResult) Apply(req *Request, resp *Response)

type TextErrorResult

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

func (TextErrorResult) Apply

func (r TextErrorResult) Apply(req *Request, resp *Response)

This method is used when the template loader or error template is not available.

type TextResult

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

func (TextResult) Apply

func (r TextResult) Apply(req *Request, resp *Response)

type XmlResult

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

func (XmlResult) Apply

func (r XmlResult) Apply(req *Request, resp *Response)

Jump to

Keyboard shortcuts

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