web

package
v1.0.6 Latest Latest
Warning

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

Go to latest
Published: Feb 20, 2020 License: MIT Imports: 23 Imported by: 0

Documentation

Index

Constants

View Source
const (
	HeaderAccept              = "Accept"
	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"
	HeaderXForwardedFor       = "X-Forwarded-For"
	HeaderXForwardedProto     = "X-Forwarded-Proto"
	HeaderXForwardedProtocol  = "X-Forwarded-Protocol"
	HeaderXForwardedSsl       = "X-Forwarded-Ssl"
	HeaderXUrlScheme          = "X-Url-Scheme"
	HeaderXHTTPMethodOverride = "X-HTTP-Method-Override"
	HeaderXRealIP             = "X-Real-IP"
	HeaderXRequestID          = "X-Request-ID"
	HeaderXRequestedWith      = "X-Requested-With"
	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"

	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"
)

Header types

View Source
const (
	MimeApplicationJSON                  = "application/json"
	MimeApplicationJSONCharsetUTF8       = MimeApplicationJSON + "; " + CharsetUTF8
	MimeApplicationJavaScript            = "application/javascript"
	MimeApplicationJavaScriptCharsetUTF8 = MimeApplicationJavaScript + "; " + CharsetUTF8
	MimeApplicationXML                   = "application/xml"
	MimeApplicationXMLCharsetUTF8        = MimeApplicationXML + "; " + CharsetUTF8
	MimeTextXML                          = "text/xml"
	MimeTextXMLCharsetUTF8               = MimeTextXML + "; " + 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 (
	CharsetUTF8 = "charset=utf8"
)

charsets

Variables

This section is empty.

Functions

This section is empty.

Types

type Context

type Context interface {
	context.Context
	AddValue(key, val interface{})

	http.Hijacker
	http.ResponseWriter
	Writer() http.ResponseWriter
	SetWriter(http.ResponseWriter)

	RouteAll() map[string]string
	Route(name string) string
	RouteInt(name string) (int, error)
	RouteInt64(name string) (int64, error)
	RouteUint64(name string) (uint64, error)
	RouteTail() string

	Request() *http.Request
	RequestURI() string
	RequestRealIP() string
	RequestHost() (ip, port string)
	RequestPage(maxPageSize int) (page, size int)
	RequestJSON(dst interface{}) error
	RequestFormFile(name string, maxSize int64) (_ *MultipartFile, closer func(), tooLarge bool)

	StatusCode() int
	Writed() int
	WebSocket(func(*websocket.Conn))
	WriteCookie(*http.Cookie)
	WriteBytes(code int, data []byte) error
	WriteString(code int, data string) error
	WriteStringf(code int, format string, v ...interface{}) error
	WriteStatus(code int) error
	WriteJSON(code int, data interface{}) error
	WritePage(data interface{}, total, size, num int) error
	WriteError(msg string) error
	WriteErrorJSON(data interface{}) error
	WriteNotFound() error
	WriteOK() error
	WriteCreated() error
	WriteCreatedID(id int) error
	WriteCreatedID64(id int64) error
	WriteNoContent() error
	WriteForbidden() error
	WriteBadRequest() error
	WriteRedirect(toURL string) error
	WriteHTML(code int, html string) error
	WriteHTMLBytes(code int, html []byte) error
	WriteHTMLTemplate(code int, tmpl *htemplate.Template, data interface{}) error
	WriteTextTemplate(code int, tmpl *ttemplate.Template, data interface{}) error
	WriteStream(code int, contentType string, r io.Reader) error
	WriteFile(filename string) error
}

Context web

func NewContext

func NewContext(w http.ResponseWriter, r *http.Request) Context

NewContext web

type Middleware

type Middleware func(View) View

Middleware view

type Middlewarer

type Middlewarer interface {
	View(View) View
}

Middlewarer alias middleware

type MultipartFile

type MultipartFile struct {
	multipart.File
	*multipart.FileHeader
}

MultipartFile utils for save

func (*MultipartFile) Close

func (mf *MultipartFile) Close()

Close file

func (*MultipartFile) Ext

func (mf *MultipartFile) Ext() string

Ext is extension of file

func (*MultipartFile) Name

func (mf *MultipartFile) Name() string

Name of file

func (*MultipartFile) Save

func (mf *MultipartFile) Save(path string)

Save file to

func (*MultipartFile) SaveToDir

func (mf *MultipartFile) SaveToDir(dir string) (path, filename string)

SaveToDir is alias Save with random name

type Router

type Router interface {
	ServeHTTP(http.ResponseWriter, *http.Request)

	ViewConverter(func(interface{}) View)
	AddMiddleware(...interface{})

	NotFound(view interface{})
	Group(path string, sub func(Router))
	Route(method, path string, view interface{})
	Get(path string, view interface{})
	Head(path string, view interface{})
	Post(path string, view interface{})
	Put(path string, view interface{})
	Patch(path string, view interface{})
	Delete(path string, view interface{})
	Connect(path string, view interface{})
	Options(path string, view interface{})
	Trace(path string, view interface{})

	Redirect(path, method, toURL string)

	File(path, filename string)
	Media(path, rootDir string)
	Static(path, rootDir string, minSizeForCompress int64)
	StaticFile(path, filename string, compress bool)
}

Router http

func NewRouter

func NewRouter() Router

NewRouter for server

type View

type View func(Context) error

View is route request view

func ViewConverter

func ViewConverter(view interface{}) View

ViewConverter default

type Viewer

type Viewer interface {
	View() View
}

Viewer is View interface

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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