web

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Feb 7, 2020 License: MIT Imports: 22 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=UTF-8"
)

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)
	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
	WriteNoContent() error
	WriteForbidden() error
	WriteBadRequest() error
	WriteRedirect(toURL string) error
	WriteHTML(code int, html string) error
	WriteTemplate(code int, tmpl *template.Template, data interface{}) error
	WriteTemplateFile(code int, filename string, 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 {
	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{})

	ServeHTTP(http.ResponseWriter, *http.Request)
}

Router http

func NewRouter

func NewRouter() Router

NewRouter for server

type StaticFileServer

type StaticFileServer struct {
	Dir             string
	GzipMinCompress float64
	GzipMinSizeKB   int
}

StaticFileServer is FileServer with static files from memory

func (StaticFileServer) View

func (fs StaticFileServer) View() View

View return fileServer view

type View

type View func(Context) error

View is route request view

func FileServer

func FileServer(pathParts ...string) View

FileServer is View for share static/media files

func Redirect

func Redirect(toURL string) View

Redirect view

func StaticFile

func StaticFile(path string) View

StaticFile view without compression

func StaticFileCompressed

func StaticFileCompressed(path string, gzipMinCompress float64, gzipMinSizeKB int) View

StaticFileCompressed view with compression

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