Context

package
v1.4.9 Latest Latest
Warning

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

Go to latest
Published: Jan 10, 2020 License: MIT Imports: 21 Imported by: 0

Documentation

Index

Constants

View Source
const (
	Dev  = "Dev"
	Prod = "Prod"
	Test = "Test"
)
View Source
const (
	MIMEApplicationJSON                  = "application/json"
	MIMEApplicationJSONCharsetUTF8       = MIMEApplicationJSON + "; " + CharsetUTF8
	MIMEApplicationJavaScript            = "application/javascript"
	MIMEApplicationJavaScriptCharsetUTF8 = MIMEApplicationJavaScript + "; " + CharsetUTF8
	MIMEApplicationXML                   = "application/xml"
	MIMEApplicationYAML                  = "application/x-yaml"
	MIMEApplicationXMLCharsetUTF8        = MIMEApplicationXML + "; " + CharsetUTF8
	MIMEApplicationForm                  = "application/x-www-form-urlencoded"
	MIMEApplicationProtobuf              = "application/protobuf"
	MIMEApplicationMsgpack               = "application/msgpack"
	MIMETextHTML                         = "text/html"
	MIMETextHTMLCharsetUTF8              = MIMETextHTML + "; " + CharsetUTF8
	MIMETextPlain                        = "text/plain"
	MIMETextPlainCharsetUTF8             = MIMETextPlain + "; " + CharsetUTF8
	MIMEMultipartForm                    = "multipart/form-data"
	MIMEOctetStream                      = "application/octet-stream"
)

MIME types

View Source
const (
	HeaderAcceptEncoding                = "Accept-Encoding"
	HeaderAllow                         = "Allow"
	HeaderAuthorization                 = "Authorization"
	HeaderContentDisposition            = "Content-Disposition"
	HeaderContentEncoding               = "Content-Encoding"
	HeaderContentLength                 = "Content-Length"
	HeaderContentType                   = "Content-Type"
	HeaderCookie                        = "Cookie"
	HeaderSetCookie                     = "Set-Cookie"
	HeaderIfModifiedSince               = "If-Modified-Since"
	HeaderLastModified                  = "Last-Modified"
	HeaderLocation                      = "Location"
	HeaderUpgrade                       = "Upgrade"
	HeaderVary                          = "Vary"
	HeaderWWWAuthenticate               = "WWW-Authenticate"
	HeaderXRequestedWith                = "X-Requested-With"
	HeaderXForwardedProto               = "X-Forwarded-Proto"
	HeaderXHTTPMethodOverride           = "X-HTTP-Method-Override"
	HeaderXForwardedFor                 = "X-Forwarded-For"
	HeaderXRealIP                       = "X-Real-IP"
	HeaderServer                        = "Server"
	HeaderOrigin                        = "Origin"
	HeaderAccessControlRequestMethod    = "Access-Control-Request-Method"
	HeaderAccessControlRequestHeaders   = "Access-Control-Request-Headers"
	HeaderAccessControlAllowOrigin      = "Access-Control-Allow-Origin"
	HeaderAccessControlAllowMethods     = "Access-Control-Allow-Methods"
	HeaderAccessControlAllowHeaders     = "Access-Control-Allow-Headers"
	HeaderAccessControlAllowCredentials = "Access-Control-Allow-Credentials"
	HeaderAccessControlExposeHeaders    = "Access-Control-Expose-Headers"
	HeaderAccessControlMaxAge           = "Access-Control-Max-Age"
	HeaderP3P                           = "P3P"
	HeaderCacheControl                  = "Cache-control"

	// Security
	HeaderStrictTransportSecurity = "Strict-Transport-Security"
	HeaderXContentTypeOptions     = "X-Content-Type-Options"
	HeaderXXSSProtection          = "X-XSS-Protection"
	HeaderXFrameOptions           = "X-Frame-Options"
	HeaderContentSecurityPolicy   = "Content-Security-Policy"
	HeaderXCSRFToken              = "X-CSRF-Token"
)

Headers

View Source
const (
	CONNECT = http.MethodConnect
	DELETE  = http.MethodDelete
	GET     = http.MethodGet
	HEAD    = http.MethodHead
	OPTIONS = http.MethodOptions
	PATCH   = http.MethodPatch
	POST    = http.MethodPost
	PUT     = http.MethodPut
	TRACE   = http.MethodTrace
)
View Source
const (
	CharsetUTF8 = "charset=utf-8"
)

Http define

Variables

Functions

func ConvertMapToStruct added in v1.4.6

func ConvertMapToStruct(tagName string, ptr interface{}, form map[string][]string) error

convert map to struct

Types

type HostEnvironment added in v1.4.0

type HostEnvironment struct {
	ApplicationName string
	Version         string
	Profile         string
	Args            []string
	Addr            string
	Port            string
	PID             int
}

func (HostEnvironment) IsDevelopment added in v1.4.0

func (env HostEnvironment) IsDevelopment() bool

func (HostEnvironment) IsProduction added in v1.4.0

func (env HostEnvironment) IsProduction() bool

func (HostEnvironment) IsStaging added in v1.4.0

func (env HostEnvironment) IsStaging() bool

type HttpContext

type HttpContext struct {
	Request          *http.Request
	Response         *responseWriter
	RouterData       url.Values
	RequiredServices DependencyInjection.IServiceProvider

	Result interface{}
	// contains filtered or unexported fields
}

func (*HttpContext) AsciiJSON

func (c *HttpContext) AsciiJSON(code int, obj interface{})

AsciiJSON serializes the given struct as JSON into the response body with unicode to ASCII string. It also sets the Content-Type as "application/json".

func (*HttpContext) Bind

func (ctx *HttpContext) Bind(i interface{}) (err error)

func (*HttpContext) Error

func (ctx *HttpContext) Error(code int, error string)

Write Error Response.

func (*HttpContext) File

func (c *HttpContext) File(filepath string)

func (*HttpContext) FileStream

func (c *HttpContext) FileStream(code int, bytes []byte)

func (*HttpContext) FormFile

func (ctx *HttpContext) FormFile(key string) (multipart.File, *multipart.FileHeader, error)

FormFile gets file from request.

func (*HttpContext) FullRemoteIP

func (ctx *HttpContext) FullRemoteIP() string

FullRemoteIP RemoteAddr to an "IP:port" address

func (*HttpContext) GetAllParam

func (ctx *HttpContext) GetAllParam() url.Values

func (*HttpContext) GetCookie

func (ctx *HttpContext) GetCookie(name string) string

Get Cookie by Name

func (*HttpContext) GetItem

func (ctx *HttpContext) GetItem(key string) interface{}

Get data in context.

func (*HttpContext) GetStatus

func (ctx *HttpContext) GetStatus() int

Get Http Status Code.

func (*HttpContext) HTML

func (ctx *HttpContext) HTML(code int, name string, obj interface{})

func (*HttpContext) Header

func (c *HttpContext) Header(key, value string)

func (*HttpContext) IndentedJSON

func (ctx *HttpContext) IndentedJSON(code int, obj interface{})

func (*HttpContext) IsAJAX

func (ctx *HttpContext) IsAJAX() bool

IsAJAX returns if it is a ajax request

func (*HttpContext) IsWebsocket

func (ctx *HttpContext) IsWebsocket() bool

func (*HttpContext) JSON

func (c *HttpContext) JSON(code int, obj interface{})

func (*HttpContext) JSONP

func (c *HttpContext) JSONP(code int, obj interface{})

func (*HttpContext) Method

func (ctx *HttpContext) Method() string

Get Http Method.

func (*HttpContext) Param

func (ctx *HttpContext) Param(name string) string

Get Post Param

func (*HttpContext) Path

func (ctx *HttpContext) Path() string

Path returns URL Path string.

func (*HttpContext) PostBody

func (ctx *HttpContext) PostBody() []byte

PostBody returns data from the POST or PUT request body

func (*HttpContext) PostForm

func (ctx *HttpContext) PostForm() url.Values

Get Post Params

func (*HttpContext) PostJsonForm

func (ctx *HttpContext) PostJsonForm() url.Values

func (*HttpContext) PostMultipartForm

func (ctx *HttpContext) PostMultipartForm() url.Values

func (*HttpContext) ProtoBuf

func (c *HttpContext) ProtoBuf(code int, obj interface{})

ProtoBuf serializes the given struct as ProtoBuf into the response body.

func (*HttpContext) PureJSON

func (c *HttpContext) PureJSON(code int, obj interface{})

PureJSON serializes the given struct as JSON into the response body. PureJSON, unlike JSON, does not replace special html characters with their unicode entities.

func (*HttpContext) Query

func (ctx *HttpContext) Query(key string) string

Get Query String By Key GET /path?id=1234&name=Manu&value= c.Query("id") == "1234" c.Query("name") == "Manu" c.Query("value") == "" c.Query("wtf") == ""

func (*HttpContext) QueryStringOrDefault

func (ctx *HttpContext) QueryStringOrDefault(key string, defaultval string) string

func (*HttpContext) QueryStrings

func (ctx *HttpContext) QueryStrings() url.Values

Get Query string

func (*HttpContext) RealIP

func (ctx *HttpContext) RealIP() string

RealIP returns the first ip from 'X-Forwarded-For' or 'X-Real-IP' header key if not exists data, returns request.RemoteAddr fixed for #164

func (*HttpContext) Redirect

func (ctx *HttpContext) Redirect(code int, url string)

Redirect redirects the request

func (*HttpContext) Referer

func (ctx *HttpContext) Referer() string

Referer returns request referer.

func (*HttpContext) RemoteIP

func (ctx *HttpContext) RemoteIP() string

RemoteIP RemoteAddr to an "IP" address

func (*HttpContext) Render

func (c *HttpContext) Render(code int, r ActionResult.IActionResult)

ActionResult writes the response headers and calls render.ActionResult to render data.

func (*HttpContext) SaveFile

func (ctx *HttpContext) SaveFile(name, saveDir string) (string, error)

SaveFile saves the form file and returns the filename.

func (*HttpContext) SecureJSON

func (c *HttpContext) SecureJSON(code int, obj interface{})

func (*HttpContext) SetCookie

func (ctx *HttpContext) SetCookie(name, value string)

Set Cookie value

func (*HttpContext) SetItem

func (ctx *HttpContext) SetItem(key string, val interface{})

Set data in context.

func (*HttpContext) Status

func (ctx *HttpContext) Status(code int)

Status sets the HTTP response code.

func (*HttpContext) Text

func (c *HttpContext) Text(code int, format string, values ...interface{})

String writes the given string into the response body.

func (*HttpContext) Url

func (ctx *HttpContext) Url() string

Url get request url

func (*HttpContext) UserAgent

func (ctx *HttpContext) UserAgent() string

UserAgent returns http request UserAgent

func (*HttpContext) Write

func (ctx *HttpContext) Write(data []byte) (n int, err error)

Write Byte[] Response.

func (*HttpContext) XML

func (c *HttpContext) XML(code int, obj interface{})

XML serializes the given struct as XML into the response body. It also sets the Content-Type as "application/xml".

func (*HttpContext) YAML

func (c *HttpContext) YAML(code int, obj interface{})

YAML serializes the given struct as YAML into the response body.

type M added in v1.4.6

type M = map[string]string

type ResponseWriter

type ResponseWriter interface {
	http.ResponseWriter
	http.Flusher
	// Status returns the status code of the response or 0 if the response has
	// not been written
	Status() int
	// Written returns whether or not the ResponseWriter has been written.
	Written() bool
	// Size returns the size of the response body.
	Size() int
	// Before allows for a function to be called before the ResponseWriter has been written to. This is
	// useful for setting headers or any other operations that must happen before a response has been written.
	Before(func(ResponseWriter))
}

ResponseWriter is a wrapper around http.ResponseWriter that provides extra information about the response. It is recommended that middleware handlers use this construct to wrap a responsewriter if the functionality calls for it.

func NewResponseWriter

func NewResponseWriter(rw http.ResponseWriter) ResponseWriter

NewResponseWriter creates a ResponseWriter that wraps an http.ResponseWriter

Jump to

Keyboard shortcuts

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