web

package
v1.1.10 Latest Latest
Warning

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

Go to latest
Published: May 19, 2020 License: MIT Imports: 26 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; " + CharsetUTF8
	MimeApplicationJavaScript = "application/javascript; " + CharsetUTF8
	MimeApplicationXML        = "application/xml; " + CharsetUTF8
	MimeTextXML               = "text/xml; " + CharsetUTF8
	MimeApplicationForm       = "application/x-www-form-urlencoded"
	MimeApplicationProtobuf   = "application/protobuf"
	MimeApplicationMsgpack    = "application/msgpack"
	MimeTextHTML              = "text/html; " + CharsetUTF8
	MimeTextPlain             = "text/plain; " + 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
	RequestUserAgent() *user_agent.UserAgent
	RequestHost() (ip, port string)
	RequestPage(maxPageSize int) (page, size int)
	RequestJSON(dst interface{}) error
	RequestJSONForm(dst JSONCheck) bool
	RequestFormFile(name string, maxSize int64) (_ *MultipartFile, closer func(), tooLarge bool)

	StatusCode() int
	Writed() int
	WebSocket(handler func(*Socket))
	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 JSONCheck added in v1.1.7

type JSONCheck interface {
	Check() bool
}

JSONCheck form

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, compress bool)
	StaticFile(path, filename string, compress bool)
}

Router http

func NewRouter

func NewRouter() Router

NewRouter for server

type Socket added in v1.1.8

type Socket struct {
	*websocket.Conn
}

Socket ws

func (*Socket) ReadJSON added in v1.1.8

func (s *Socket) ReadJSON(dst interface{}) error

ReadJSON frame

func (*Socket) WriteJSON added in v1.1.8

func (s *Socket) WriteJSON(data interface{}) error

WriteJSON frame

func (*Socket) WriteString added in v1.1.9

func (s *Socket) WriteString(text string) error

WriteString text

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