Documentation ¶
Index ¶
- Constants
- Variables
- func HTTPNotFound(ctx Context)
- func NewInnerRenderer() *innerRenderer
- func NewRouter(server *HttpServer) *router
- type BaseMiddlware
- type Binder
- type Context
- type DotWeb
- func (app *DotWeb) Cache() cache.Cache
- func (app *DotWeb) Close() error
- func (app *DotWeb) DefaultHTTPErrorHandler(ctx Context, err error)
- func (app *DotWeb) DefaultMethodNotAllowedHandler(ctx Context)
- func (app *DotWeb) DefaultNotFoundHandler(ctx Context)
- func (app *DotWeb) GetMiddlewareFunc(name string) (MiddlewareFunc, bool)
- func (app *DotWeb) IsDevelopmentMode() bool
- func (app *DotWeb) ListenAndServe(addr string) error
- func (app *DotWeb) MustStart()
- func (app *DotWeb) RegisterMiddlewareFunc(name string, middleFunc MiddlewareFunc)
- func (app *DotWeb) RunMode() string
- func (app *DotWeb) SetCache(ca cache.Cache)
- func (app *DotWeb) SetConfig(config *config.Config) error
- func (app *DotWeb) SetDevelopmentMode()
- func (app *DotWeb) SetEnabledLog(enabledLog bool)
- func (app *DotWeb) SetExceptionHandle(handler ExceptionHandle)
- func (app *DotWeb) SetLogPath(path string)
- func (app *DotWeb) SetLogger(log logger.AppLog)
- func (app *DotWeb) SetMethodNotAllowedHandle(handler StandardHandle)
- func (app *DotWeb) SetNotFoundHandle(handler StandardHandle)
- func (app *DotWeb) SetPProfConfig(enabledPProf bool, httpport int)
- func (app *DotWeb) SetProductionMode()
- func (app *DotWeb) Shutdown(ctx context.Context) error
- func (app *DotWeb) Start() error
- func (app *DotWeb) StartServer(httpPort int) error
- func (app *DotWeb) Use(m ...Middleware)
- func (app *DotWeb) UseRequestLog()
- type ExceptionHandle
- type Group
- type HijackConn
- type HttpContext
- func (ctx *HttpContext) AppContext() *core.ItemContext
- func (ctx *HttpContext) AppSetConfig() *core.ItemContext
- func (ctx *HttpContext) Attachment(file, name string) (err error)
- func (ctx *HttpContext) Bind(i interface{}) error
- func (ctx *HttpContext) Cache() cache.Cache
- func (ctx *HttpContext) Context() context.Context
- func (ctx *HttpContext) End()
- func (ctx *HttpContext) Features() *xFeatureTools
- func (ctx *HttpContext) File(file string) (err error)
- func (ctx *HttpContext) FormValue(key string) string
- func (ctx *HttpContext) GetRouterName(key string) string
- func (ctx *HttpContext) Handler() HttpHandle
- func (ctx *HttpContext) Hijack() (*HijackConn, error)
- func (ctx *HttpContext) HijackConn() *HijackConn
- func (ctx *HttpContext) HttpServer() *HttpServer
- func (ctx *HttpContext) Inline(file, name string) (err error)
- func (ctx *HttpContext) IsEnd() bool
- func (ctx *HttpContext) IsHijack() bool
- func (ctx *HttpContext) IsWebSocket() bool
- func (ctx *HttpContext) Items() *core.ItemContext
- func (ctx *HttpContext) PostFormValue(key string) string
- func (ctx *HttpContext) QueryString(key string) string
- func (ctx *HttpContext) ReadCookie(name string) (*http.Cookie, error)
- func (ctx *HttpContext) ReadCookieValue(name string) (string, error)
- func (ctx *HttpContext) Redirect(code int, targetUrl string) error
- func (ctx *HttpContext) RemoteIP() string
- func (ctx *HttpContext) RemoveCookie(name string)
- func (ctx *HttpContext) Request() *Request
- func (ctx *HttpContext) Response() *Response
- func (ctx *HttpContext) RouterNode() RouterNode
- func (ctx *HttpContext) RouterParams() Params
- func (ctx *HttpContext) Session() (state *session.SessionState)
- func (ctx *HttpContext) SessionID() string
- func (ctx *HttpContext) SetCookie(cookie *http.Cookie)
- func (ctx *HttpContext) SetCookieValue(name, value string, maxAge int)
- func (ctx *HttpContext) SetTimeoutContext(timeout time.Duration) context.Context
- func (ctx *HttpContext) View(name string) error
- func (ctx *HttpContext) ViewC(code int, name string) error
- func (ctx *HttpContext) ViewData() *core.ItemContext
- func (ctx *HttpContext) WebSocket() *WebSocket
- func (ctx *HttpContext) WithContext(runCtx context.Context)
- func (ctx *HttpContext) Write(code int, content []byte) (int, error)
- func (ctx *HttpContext) WriteBlob(contentType string, b []byte) (int, error)
- func (ctx *HttpContext) WriteBlobC(code int, contentType string, b []byte) (int, error)
- func (ctx *HttpContext) WriteHtml(contents ...interface{}) (int, error)
- func (ctx *HttpContext) WriteHtmlC(code int, contents ...interface{}) (int, error)
- func (ctx *HttpContext) WriteJson(i interface{}) (int, error)
- func (ctx *HttpContext) WriteJsonBlob(b []byte) (int, error)
- func (ctx *HttpContext) WriteJsonBlobC(code int, b []byte) (int, error)
- func (ctx *HttpContext) WriteJsonC(code int, i interface{}) (int, error)
- func (ctx *HttpContext) WriteJsonp(callback string, i interface{}) (int, error)
- func (ctx *HttpContext) WriteJsonpBlob(callback string, b []byte) (size int, err error)
- func (ctx *HttpContext) WriteString(contents ...interface{}) (int, error)
- func (ctx *HttpContext) WriteStringC(code int, contents ...interface{}) (int, error)
- type HttpHandle
- type HttpModule
- type HttpServer
- func (server *HttpServer) Any(path string, handle HttpHandle)
- func (server *HttpServer) Binder() Binder
- func (server *HttpServer) DELETE(path string, handle HttpHandle) RouterNode
- func (server *HttpServer) GET(path string, handle HttpHandle) RouterNode
- func (server *HttpServer) GetSessionManager() *session.SessionManager
- func (server *HttpServer) Group(prefix string) Group
- func (server *HttpServer) HEAD(path string, handle HttpHandle) RouterNode
- func (server *HttpServer) HiJack(path string, handle HttpHandle)
- func (server *HttpServer) IndexPage() string
- func (server *HttpServer) InitSessionManager()
- func (server *HttpServer) IsOffline() bool
- func (server *HttpServer) ListenAndServe(addr string) error
- func (server *HttpServer) ListenAndServeTLS(addr string, certFile, keyFile string) error
- func (server *HttpServer) OPTIONS(path string, handle HttpHandle) RouterNode
- func (server *HttpServer) PATCH(path string, handle HttpHandle) RouterNode
- func (server *HttpServer) POST(path string, handle HttpHandle) RouterNode
- func (server *HttpServer) PUT(path string, handle HttpHandle) RouterNode
- func (server *HttpServer) RegisterModule(module *HttpModule)
- func (server *HttpServer) Renderer() Renderer
- func (server *HttpServer) Router() Router
- func (server *HttpServer) ServeHTTP(w http.ResponseWriter, req *http.Request)
- func (server *HttpServer) ServerConfig() *config.ServerNode
- func (server *HttpServer) ServerFile(path string, fileroot string) RouterNode
- func (server *HttpServer) SessionConfig() *config.SessionNode
- func (server *HttpServer) SetEnabledAutoHEAD(autoHEAD bool)
- func (server *HttpServer) SetEnabledDetailRequestData(isEnabled bool)
- func (server *HttpServer) SetEnabledGzip(isEnabled bool)
- func (server *HttpServer) SetEnabledIgnoreFavicon(isEnabled bool)
- func (server *HttpServer) SetEnabledListDir(isEnabled bool)
- func (server *HttpServer) SetEnabledSession(isEnabled bool)
- func (server *HttpServer) SetEnabledTLS(isEnabled bool, certFile, keyFile string)
- func (server *HttpServer) SetOffline(offline bool, offlineText string, offlineUrl string)
- func (server *HttpServer) SetRenderer(r Renderer)
- func (server *HttpServer) SetSessionConfig(storeConfig *session.StoreConfig)
- func (server *HttpServer) WebSocket(path string, handle HttpHandle)
- type LogJson
- type Middleware
- type MiddlewareFunc
- type Node
- type Param
- type Params
- type Renderer
- type Request
- func (req *Request) ContentType() string
- func (req *Request) FormFile(key string) (*UploadFile, error)
- func (req *Request) FormValues() map[string][]string
- func (req *Request) FullRemoteIP() string
- func (req *Request) IsAJAX() bool
- func (req *Request) Path() string
- func (req *Request) PostBody() []byte
- func (req *Request) PostString(key string) stringdeprecated
- func (req *Request) QueryHeader(key string) string
- func (req *Request) QueryString(key string) string
- func (req *Request) QueryStrings() url.Values
- func (req *Request) RawQuery() string
- func (req *Request) RemoteIP() string
- func (req *Request) RequestID() string
- func (req *Request) Url() string
- type RequestLogMiddleware
- type Response
- func (r *Response) Body() []byte
- func (r *Response) BodyString() string
- func (r *Response) End()
- func (r *Response) Flush()
- func (r *Response) Header() http.Header
- func (r *Response) Hijack() (net.Conn, *bufio.ReadWriter, error)
- func (r *Response) HttpCode() int
- func (r *Response) QueryHeader(key string) string
- func (r *Response) Redirect(code int, targetUrl string) error
- func (r *Response) SetContentType(contenttype string)
- func (r *Response) SetHeader(key, val string)
- func (r *Response) SetStatusCode(code int) error
- func (r *Response) SetWriter(w http.ResponseWriter) *Response
- func (r *Response) Write(code int, b []byte) (n int, err error)
- func (r *Response) WriteHeader(code int) error
- func (r *Response) Writer() http.ResponseWriter
- type Router
- type RouterHandle
- type RouterNode
- type StandardHandle
- type UploadFile
- type ValueNode
- type WebSocket
Constants ¶
const ( LogTarget_Default = "dotweb_default" LogTarget_HttpRequest = "dotweb_request" LogTarget_HttpServer = "dotweb_server" LogLevel_Debug = "debug" LogLevel_Info = "info" LogLevel_Warn = "warn" LogLevel_Error = "error" )
Log define
const ( CharsetUTF8 = "text/plain; charset=utf-8" DefaultServerName = "dotweb" )
Http define
const ( MIMEApplicationJSON = "application/json" MIMEApplicationJSONCharsetUTF8 = MIMEApplicationJSON + "; " + CharsetUTF8 MIMEApplicationJavaScript = "application/javascript" MIMEApplicationJavaScriptCharsetUTF8 = MIMEApplicationJavaScript + "; " + CharsetUTF8 MIMEApplicationXML = "application/xml" 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
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
const ( DefaultHTTPPort = 8080 //DefaultHTTPPort default http port; fixed for #70 UPDATE default http port 80 to 8080 RunMode_Development = "development" RunMode_Production = "production" )
const ( RouteMethod_Any = "ANY" RouteMethod_GET = "GET" RouteMethod_HEAD = "HEAD" RouteMethod_OPTIONS = "OPTIONS" RouteMethod_POST = "POST" RouteMethod_PUT = "PUT" RouteMethod_PATCH = "PATCH" RouteMethod_DELETE = "DELETE" RouteMethod_HiJack = "HIJACK" RouteMethod_WebSocket = "WEBSOCKET" )
const ( DefaultGzipLevel = 9 DefaultIndexPage = "index.html" )
Variables ¶
var FeatureTools *xFeatureTools
var (
HttpMethodMap map[string]string
)
Functions ¶
func HTTPNotFound ¶
func HTTPNotFound(ctx Context)
HTTPNotFound simple notfound function for Context
func NewInnerRenderer ¶
func NewInnerRenderer() *innerRenderer
NewInnerRenderer create a inner renderer instance
func NewRouter ¶
func NewRouter(server *HttpServer) *router
New returns a new initialized Router. Path auto-correction, including trailing slashes, is enabled by default.
Types ¶
type BaseMiddlware ¶
type BaseMiddlware struct {
// contains filtered or unexported fields
}
middleware 基础类,应用可基于此实现完整Moddleware
func (*BaseMiddlware) Next ¶
func (bm *BaseMiddlware) Next(ctx Context) error
func (*BaseMiddlware) SetNext ¶
func (bm *BaseMiddlware) SetNext(m Middleware)
type Context ¶
type Context interface { Context() context.Context SetTimeoutContext(timeout time.Duration) context.Context WithContext(runCtx context.Context) HttpServer() *HttpServer Response() *Response Request() *Request WebSocket() *WebSocket HijackConn() *HijackConn RouterNode() RouterNode RouterParams() Params Handler() HttpHandle AppContext() *core.ItemContext Cache() cache.Cache Items() *core.ItemContext AppSetConfig() *core.ItemContext ViewData() *core.ItemContext SessionID() string Session() (state *session.SessionState) Hijack() (*HijackConn, error) IsHijack() bool IsWebSocket() bool End() IsEnd() bool Redirect(code int, targetUrl string) error QueryString(key string) string FormValue(key string) string PostFormValue(key string) string File(file string) (err error) Attachment(file string, name string) error Inline(file string, name string) error Bind(i interface{}) error GetRouterName(key string) string RemoteIP() string SetCookieValue(name, value string, maxAge int) SetCookie(cookie *http.Cookie) RemoveCookie(name string) ReadCookieValue(name string) (string, error) ReadCookie(name string) (*http.Cookie, error) View(name string) error ViewC(code int, name string) error Write(code int, content []byte) (int, error) WriteString(contents ...interface{}) (int, error) WriteStringC(code int, contents ...interface{}) (int, error) WriteHtml(contents ...interface{}) (int, error) WriteHtmlC(code int, contents ...interface{}) (int, error) WriteBlob(contentType string, b []byte) (int, error) WriteBlobC(code int, contentType string, b []byte) (int, error) WriteJson(i interface{}) (int, error) WriteJsonC(code int, i interface{}) (int, error) WriteJsonBlob(b []byte) (int, error) WriteJsonBlobC(code int, b []byte) (int, error) WriteJsonp(callback string, i interface{}) (int, error) WriteJsonpBlob(callback string, b []byte) (size int, err error) }
type DotWeb ¶
type DotWeb struct { HttpServer *HttpServer OfflineServer servers.Server Config *config.Config Middlewares []Middleware ExceptionHandler ExceptionHandle NotFoundHandler StandardHandle // NotFoundHandler 支持自定义404处理代码能力 MethodNotAllowedHandler StandardHandle // MethodNotAllowedHandler fixed for #64 增加MethodNotAllowed自定义处理 AppContext *core.ItemContext // contains filtered or unexported fields }
func (*DotWeb) Close ¶
Close immediately stops the server. It internally calls `http.Server#Close()`.
func (*DotWeb) DefaultHTTPErrorHandler ¶
DefaultHTTPErrorHandler default exception handler
func (*DotWeb) DefaultMethodNotAllowedHandler ¶
DefaultMethodNotAllowedHandler default exception handler
func (*DotWeb) DefaultNotFoundHandler ¶
DefaultNotFoundHandler default exception handler
func (*DotWeb) GetMiddlewareFunc ¶
func (app *DotWeb) GetMiddlewareFunc(name string) (MiddlewareFunc, bool)
GetMiddlewareFunc get middleware with gived name
func (*DotWeb) IsDevelopmentMode ¶
IsDevelopmentMode check current run mode is development mode
func (*DotWeb) ListenAndServe ¶
ListenAndServe start server with addr not support pprof server auto start
func (*DotWeb) MustStart ¶
func (app *DotWeb) MustStart()
MustStart start app server with set config If an exception occurs, will be panic it if no set Server.Port, will be use DefaultHttpPort
func (*DotWeb) RegisterMiddlewareFunc ¶
func (app *DotWeb) RegisterMiddlewareFunc(name string, middleFunc MiddlewareFunc)
RegisterMiddlewareFunc register middleware with gived name & middleware
func (*DotWeb) SetDevelopmentMode ¶
func (app *DotWeb) SetDevelopmentMode()
SetDevelopmentMode set run mode on development mode
func (*DotWeb) SetEnabledLog ¶
SetEnabledLog set enabled log flag
func (*DotWeb) SetExceptionHandle ¶
func (app *DotWeb) SetExceptionHandle(handler ExceptionHandle)
SetExceptionHandle set custom error handler
func (*DotWeb) SetLogger ¶
SetLogger set user logger, the logger must implement logger.AppLog interface
func (*DotWeb) SetMethodNotAllowedHandle ¶
func (app *DotWeb) SetMethodNotAllowedHandle(handler StandardHandle)
SetMethodNotAllowedHandle set custom 405 handler
func (*DotWeb) SetNotFoundHandle ¶
func (app *DotWeb) SetNotFoundHandle(handler StandardHandle)
SetNotFoundHandle set custom 404 handler
func (*DotWeb) SetPProfConfig ¶
SetPProfConfig set pprofserver config, default is disable and don't use same port with StartServer
func (*DotWeb) SetProductionMode ¶
func (app *DotWeb) SetProductionMode()
SetProductionMode set run mode on production mode
func (*DotWeb) Shutdown ¶
Shutdown stops server the gracefully. It internally calls `http.Server#Shutdown()`.
func (*DotWeb) Start ¶
Start start app server with set config If an exception occurs, will be return it if no set Server.Port, will be use DefaultHttpPort
func (*DotWeb) StartServer ¶
StartServer start server with http port if config the pprof, will be start pprof server
func (*DotWeb) UseRequestLog ¶
func (app *DotWeb) UseRequestLog()
UseRequestLog register RequestLog middleware
type Group ¶
type Group interface { Use(m ...Middleware) Group Group(prefix string, m ...Middleware) Group DELETE(path string, h HttpHandle) RouterNode GET(path string, h HttpHandle) RouterNode HEAD(path string, h HttpHandle) RouterNode OPTIONS(path string, h HttpHandle) RouterNode PATCH(path string, h HttpHandle) RouterNode POST(path string, h HttpHandle) RouterNode PUT(path string, h HttpHandle) RouterNode RegisterRoute(method, path string, h HttpHandle) RouterNode }
func NewGroup ¶
func NewGroup(prefix string, server *HttpServer) Group
type HijackConn ¶
type HijackConn struct { ReadWriter *bufio.ReadWriter Conn net.Conn // contains filtered or unexported fields }
hijack conn
func (*HijackConn) SetHeader ¶
func (hj *HijackConn) SetHeader(key, value string)
SetHeader hjiack conn write header
func (*HijackConn) WriteBlob ¶
func (hj *HijackConn) WriteBlob(p []byte) (size int, err error)
WriteBlob hjiack conn write []byte
func (*HijackConn) WriteString ¶
func (hj *HijackConn) WriteString(content string) (int, error)
WriteString hjiack conn write string
type HttpContext ¶
type HttpContext struct {
// contains filtered or unexported fields
}
func (*HttpContext) AppContext ¶
func (ctx *HttpContext) AppContext() *core.ItemContext
AppContext get application's global appcontext issue #3
func (*HttpContext) AppSetConfig ¶
func (ctx *HttpContext) AppSetConfig() *core.ItemContext
AppSetConfig get appset from config file update for issue #16 配置文件
func (*HttpContext) Attachment ¶
func (ctx *HttpContext) Attachment(file, name string) (err error)
Attachment sends a response as attachment, prompting client to save the file. for issue #39
func (*HttpContext) Bind ¶
func (ctx *HttpContext) Bind(i interface{}) error
* 支持Json、Xml、Form提交的属性绑定
func (*HttpContext) Cache ¶
func (ctx *HttpContext) Cache() cache.Cache
Cache get application's global cache
func (*HttpContext) Context ¶
func (ctx *HttpContext) Context() context.Context
Context return context.Context
func (*HttpContext) End ¶
func (ctx *HttpContext) End()
End set context user handler process end if set HttpContext.End,ignore user handler, but exec all http module - fixed issue #5
func (*HttpContext) Features ¶
func (ctx *HttpContext) Features() *xFeatureTools
func (*HttpContext) File ¶
func (ctx *HttpContext) File(file string) (err error)
File sends a response with the content of the file if file not exists, response 404 for issue #39
func (*HttpContext) FormValue ¶
func (ctx *HttpContext) FormValue(key string) string
* 根据指定key获取包括在post、put和get内的值
func (*HttpContext) GetRouterName ¶
func (ctx *HttpContext) GetRouterName(key string) string
func (*HttpContext) Handler ¶
func (ctx *HttpContext) Handler() HttpHandle
func (*HttpContext) Hijack ¶
func (ctx *HttpContext) Hijack() (*HijackConn, error)
Hijack make current connection to hijack mode
func (*HttpContext) HijackConn ¶
func (ctx *HttpContext) HijackConn() *HijackConn
func (*HttpContext) HttpServer ¶
func (ctx *HttpContext) HttpServer() *HttpServer
HttpServer return HttpServer
func (*HttpContext) Inline ¶
func (ctx *HttpContext) Inline(file, name string) (err error)
Inline sends a response as inline, opening the file in the browser. if file not exists, response 404 for issue #39
func (*HttpContext) IsEnd ¶
func (ctx *HttpContext) IsEnd() bool
func (*HttpContext) IsHijack ¶
func (ctx *HttpContext) IsHijack() bool
func (*HttpContext) IsWebSocket ¶
func (ctx *HttpContext) IsWebSocket() bool
func (*HttpContext) Items ¶
func (ctx *HttpContext) Items() *core.ItemContext
Items get request's tem context lazy init when first use
func (*HttpContext) PostFormValue ¶
func (ctx *HttpContext) PostFormValue(key string) string
* 根据指定key获取包括在post、put内的值
func (*HttpContext) QueryString ¶
func (ctx *HttpContext) QueryString(key string) string
* 根据指定key获取在Get请求中对应参数值
func (*HttpContext) ReadCookie ¶
func (ctx *HttpContext) ReadCookie(name string) (*http.Cookie, error)
ReadCookie read cookie object for name
func (*HttpContext) ReadCookieValue ¶
func (ctx *HttpContext) ReadCookieValue(name string) (string, error)
ReadCookieValue read cookie value for name
func (*HttpContext) Redirect ¶
func (ctx *HttpContext) Redirect(code int, targetUrl string) error
Redirect redirect replies to the request with a redirect to url and with httpcode default you can use http.StatusFound
func (*HttpContext) RemoteIP ¶
func (ctx *HttpContext) RemoteIP() string
RemoteIP return user IP address
func (*HttpContext) RemoveCookie ¶
func (ctx *HttpContext) RemoveCookie(name string)
RemoveCookie remove cookie for path&name
func (*HttpContext) Request ¶
func (ctx *HttpContext) Request() *Request
func (*HttpContext) Response ¶
func (ctx *HttpContext) Response() *Response
func (*HttpContext) RouterNode ¶
func (ctx *HttpContext) RouterNode() RouterNode
func (*HttpContext) RouterParams ¶
func (ctx *HttpContext) RouterParams() Params
func (*HttpContext) Session ¶
func (ctx *HttpContext) Session() (state *session.SessionState)
Session get session state in current context
func (*HttpContext) SessionID ¶
func (ctx *HttpContext) SessionID() string
func (*HttpContext) SetCookie ¶
func (ctx *HttpContext) SetCookie(cookie *http.Cookie)
SetCookie write cookie with cookie-obj
func (*HttpContext) SetCookieValue ¶
func (ctx *HttpContext) SetCookieValue(name, value string, maxAge int)
SetCookieValue write cookie for name & value & maxAge default path = "/" default domain = current domain default maxAge = 0 //seconds seconds=0 means no 'Max-Age' attribute specified. seconds<0 means delete cookie now, equivalently 'Max-Age: 0' seconds>0 means Max-Age attribute present and given in seconds
func (*HttpContext) SetTimeoutContext ¶
func (ctx *HttpContext) SetTimeoutContext(timeout time.Duration) context.Context
SetTimeoutContext set new Timeout Context set Context & cancle withvalue RequestID
func (*HttpContext) View ¶
func (ctx *HttpContext) View(name string) error
View write view content to response
func (*HttpContext) ViewC ¶
func (ctx *HttpContext) ViewC(code int, name string) error
ViewC write (httpCode, view content) to response
func (*HttpContext) ViewData ¶
func (ctx *HttpContext) ViewData() *core.ItemContext
ViewData get view data context lazy init when first use
func (*HttpContext) WebSocket ¶
func (ctx *HttpContext) WebSocket() *WebSocket
func (*HttpContext) WithContext ¶
func (ctx *HttpContext) WithContext(runCtx context.Context)
WithContext set Context with RequestID
func (*HttpContext) Write ¶
func (ctx *HttpContext) Write(code int, content []byte) (int, error)
Write write code and content content to response
func (*HttpContext) WriteBlob ¶
func (ctx *HttpContext) WriteBlob(contentType string, b []byte) (int, error)
WriteBlob write []byte content to response
func (*HttpContext) WriteBlobC ¶
WriteBlobC write (httpCode, []byte) to response
func (*HttpContext) WriteHtml ¶
func (ctx *HttpContext) WriteHtml(contents ...interface{}) (int, error)
WriteString write (200, string, text/html) to response
func (*HttpContext) WriteHtmlC ¶
func (ctx *HttpContext) WriteHtmlC(code int, contents ...interface{}) (int, error)
WriteHtmlC write (httpCode, string, text/html) to response
func (*HttpContext) WriteJson ¶
func (ctx *HttpContext) WriteJson(i interface{}) (int, error)
WriteJson write (httpCode, json string) to response auto convert interface{} to json string
func (*HttpContext) WriteJsonBlob ¶
func (ctx *HttpContext) WriteJsonBlob(b []byte) (int, error)
WriteJsonBlob write json []byte to response
func (*HttpContext) WriteJsonBlobC ¶
func (ctx *HttpContext) WriteJsonBlobC(code int, b []byte) (int, error)
WriteJsonBlobC write (httpCode, json []byte) to response
func (*HttpContext) WriteJsonC ¶
func (ctx *HttpContext) WriteJsonC(code int, i interface{}) (int, error)
WriteJsonC write (httpCode, json string) to response auto convert interface{} to json string
func (*HttpContext) WriteJsonp ¶
func (ctx *HttpContext) WriteJsonp(callback string, i interface{}) (int, error)
WriteJsonp write jsonp string to response
func (*HttpContext) WriteJsonpBlob ¶
func (ctx *HttpContext) WriteJsonpBlob(callback string, b []byte) (size int, err error)
WriteJsonpBlob write jsonp string as []byte to response
func (*HttpContext) WriteString ¶
func (ctx *HttpContext) WriteString(contents ...interface{}) (int, error)
WriteString write (200, string, text/plain) to response
func (*HttpContext) WriteStringC ¶
func (ctx *HttpContext) WriteStringC(code int, contents ...interface{}) (int, error)
WriteStringC write (httpCode, string, text/plain) to response
type HttpHandle ¶
Handle is a function that can be registered to a route to handle HTTP requests. Like http.HandlerFunc, but has a special parameter Context contain all request and response data.
type HttpModule ¶
type HttpModule struct { Name string //响应请求时作为 HTTP 执行管线链中的第一个事件发生 OnBeginRequest func(Context) //响应请求时作为 HTTP 执行管线链中的最后一个事件发生。 OnEndRequest func(Context) }
HttpModule global module in http server it will be no effect when websocket request or use offline mode
type HttpServer ¶
type HttpServer struct { Modules []*HttpModule DotApp *DotWeb Features *feature.Feature // contains filtered or unexported fields }
HttpServer定义
func NewHttpServer ¶
func NewHttpServer() *HttpServer
func (*HttpServer) Any ¶
func (server *HttpServer) Any(path string, handle HttpHandle)
ANY is a shortcut for router.Handle("Any", path, handle) it support GET\HEAD\POST\PUT\PATCH\OPTIONS\DELETE
func (*HttpServer) Binder ¶
func (server *HttpServer) Binder() Binder
Binder get binder interface in server
func (*HttpServer) DELETE ¶
func (server *HttpServer) DELETE(path string, handle HttpHandle) RouterNode
DELETE is a shortcut for router.Handle("DELETE", path, handle)
func (*HttpServer) GET ¶
func (server *HttpServer) GET(path string, handle HttpHandle) RouterNode
GET is a shortcut for router.Handle("GET", path, handle)
func (*HttpServer) GetSessionManager ¶
func (server *HttpServer) GetSessionManager() *session.SessionManager
GetSessionManager get session manager in current httpserver
func (*HttpServer) Group ¶
func (server *HttpServer) Group(prefix string) Group
Group create new group with current HttpServer
func (*HttpServer) HEAD ¶
func (server *HttpServer) HEAD(path string, handle HttpHandle) RouterNode
HEAD is a shortcut for router.Handle("HEAD", path, handle)
func (*HttpServer) HiJack ¶
func (server *HttpServer) HiJack(path string, handle HttpHandle)
HiJack is a shortcut for router.HiJack(path, handle)
func (*HttpServer) IndexPage ¶
func (server *HttpServer) IndexPage() string
IndexPage default index page name
func (*HttpServer) InitSessionManager ¶
func (server *HttpServer) InitSessionManager()
InitSessionManager init session manager
func (*HttpServer) IsOffline ¶
func (server *HttpServer) IsOffline() bool
IsOffline check server is set offline state
func (*HttpServer) ListenAndServe ¶
func (server *HttpServer) ListenAndServe(addr string) error
ListenAndServe listens on the TCP network address srv.Addr and then calls Serve to handle requests on incoming connections.
func (*HttpServer) ListenAndServeTLS ¶
func (server *HttpServer) ListenAndServeTLS(addr string, certFile, keyFile string) error
ListenAndServeTLS listens on the TCP network address srv.Addr and then calls Serve to handle requests on incoming TLS connections. Accepted connections are configured to enable TCP keep-alives.
Filenames containing a certificate and matching private key for the server must be provided if neither the Server's TLSConfig.Certificates nor TLSConfig.GetCertificate are populated. If the certificate is signed by a certificate authority, the certFile should be the concatenation of the server's certificate, any intermediates, and the CA's certificate.
If srv.Addr is blank, ":https" is used.
ListenAndServeTLS always returns a non-nil error.
func (*HttpServer) OPTIONS ¶
func (server *HttpServer) OPTIONS(path string, handle HttpHandle) RouterNode
OPTIONS is a shortcut for router.Handle("OPTIONS", path, handle)
func (*HttpServer) PATCH ¶
func (server *HttpServer) PATCH(path string, handle HttpHandle) RouterNode
PATCH is a shortcut for router.Handle("PATCH", path, handle)
func (*HttpServer) POST ¶
func (server *HttpServer) POST(path string, handle HttpHandle) RouterNode
POST is a shortcut for router.Handle("POST", path, handle)
func (*HttpServer) PUT ¶
func (server *HttpServer) PUT(path string, handle HttpHandle) RouterNode
PUT is a shortcut for router.Handle("PUT", path, handle)
func (*HttpServer) RegisterModule ¶
func (server *HttpServer) RegisterModule(module *HttpModule)
RegisterModule 添加处理模块
func (*HttpServer) Renderer ¶
func (server *HttpServer) Renderer() Renderer
Renderer get renderer interface in server if no set, init InnerRenderer
func (*HttpServer) Router ¶
func (server *HttpServer) Router() Router
Router get router interface in server
func (*HttpServer) ServeHTTP ¶
func (server *HttpServer) ServeHTTP(w http.ResponseWriter, req *http.Request)
ServeHTTP make sure request can be handled correctly
func (*HttpServer) ServerConfig ¶
func (server *HttpServer) ServerConfig() *config.ServerNode
ServerConfig a shortcut for App.Config.ServerConfig
func (*HttpServer) ServerFile ¶
func (server *HttpServer) ServerFile(path string, fileroot string) RouterNode
ServerFile is a shortcut for router.ServeFiles(path, filepath) simple demo:server.ServerFile("/src/*filepath", "/var/www")
func (*HttpServer) SessionConfig ¶
func (server *HttpServer) SessionConfig() *config.SessionNode
SessionConfig a shortcut for App.Config.SessionConfig
func (*HttpServer) SetEnabledAutoHEAD ¶
func (server *HttpServer) SetEnabledAutoHEAD(autoHEAD bool)
SetEnabledAutoHEAD set EnabledAutoHEAD true or false
func (*HttpServer) SetEnabledDetailRequestData ¶
func (server *HttpServer) SetEnabledDetailRequestData(isEnabled bool)
SetEnabledDetailRequestData 设置是否启用详细请求数据统计,默认为false
func (*HttpServer) SetEnabledGzip ¶
func (server *HttpServer) SetEnabledGzip(isEnabled bool)
SetEnabledGzip 设置是否启用gzip,默认为false
func (*HttpServer) SetEnabledIgnoreFavicon ¶
func (server *HttpServer) SetEnabledIgnoreFavicon(isEnabled bool)
SetEnabledIgnoreFavicon set IgnoreFavicon Enabled default is false
func (*HttpServer) SetEnabledListDir ¶
func (server *HttpServer) SetEnabledListDir(isEnabled bool)
SetEnabledListDir 设置是否允许目录浏览,默认为false
func (*HttpServer) SetEnabledSession ¶
func (server *HttpServer) SetEnabledSession(isEnabled bool)
SetEnabledSession 设置是否启用Session,默认为false
func (*HttpServer) SetEnabledTLS ¶
func (server *HttpServer) SetEnabledTLS(isEnabled bool, certFile, keyFile string)
SetEnabledTLS set tls enabled default is false if it's true, must input certificate\private key fileName
func (*HttpServer) SetOffline ¶
func (server *HttpServer) SetOffline(offline bool, offlineText string, offlineUrl string)
SetOffline set server offline config
func (*HttpServer) SetRenderer ¶
func (server *HttpServer) SetRenderer(r Renderer)
SetRenderer set custom renderer in server
func (*HttpServer) SetSessionConfig ¶
func (server *HttpServer) SetSessionConfig(storeConfig *session.StoreConfig)
SetSessionConfig set session store config
func (*HttpServer) WebSocket ¶
func (server *HttpServer) WebSocket(path string, handle HttpHandle)
WebSocket is a shortcut for router.WebSocket(path, handle)
type Middleware ¶
type Middleware interface { Handle(ctx Context) error SetNext(m Middleware) Next(ctx Context) error }
Middleware middleware interface
type MiddlewareFunc ¶
type MiddlewareFunc func() Middleware
type Node ¶
type Node struct {
// contains filtered or unexported fields
}
func (*Node) Middlewares ¶
func (n *Node) Middlewares() []Middleware
type Params ¶
type Params []Param
Params is a Param-slice, as returned by the router. The slice is ordered, the first URL parameter is also the first slice value. It is therefore safe to read values by the index.
type Renderer ¶
type Renderer interface { //set default template path, support multi path //模板查找顺序从最后一个插入的元素开始往前找 //默认添加base、base/templates、base/views SetTemplatePath(path ...string) Render(io.Writer, string, interface{}, Context) error }
Renderer is the interface that wraps the render method.
type Request ¶
func (*Request) ContentType ¶
func (*Request) FormValues ¶
* 获取包括post、put和get内的值
func (*Request) FullRemoteIP ¶
RemoteAddr to an "IP:port" address
func (*Request) Path ¶
Path returns requested path.
The path is valid until returning from RequestHandler.
func (*Request) PostString
deprecated
func (*Request) QueryHeader ¶
func (*Request) QueryString ¶
* 根据指定key获取在Get请求中对应参数值
func (*Request) QueryStrings ¶
QueryStrings 返回Get请求方式下查询字符串map表示
type RequestLogMiddleware ¶
type RequestLogMiddleware struct {
BaseMiddlware
}
请求日志中间件
func (*RequestLogMiddleware) Handle ¶
func (m *RequestLogMiddleware) Handle(ctx Context) error
type Response ¶
func NewResponse ¶
func NewResponse(w http.ResponseWriter) (r *Response)
func (*Response) BodyString ¶
func (*Response) Flush ¶
func (r *Response) Flush()
Flush implements the http.Flusher interface to allow an HTTP handler to flush buffered data to the client. See http.Flusher(https://golang.org/pkg/net/http/#Flusher)
func (*Response) Hijack ¶
Hijack implements the http.Hijacker interface to allow an HTTP handler to take over the connection. See https://golang.org/pkg/net/http/#Hijacker
func (*Response) QueryHeader ¶
func (*Response) SetContentType ¶
func (*Response) SetStatusCode ¶
func (*Response) WriteHeader ¶
WriteHeader sends an HTTP response header with status code. If WriteHeader is not called explicitly, the first call to Write will trigger an implicit WriteHeader(http.StatusOK). Thus explicit calls to WriteHeader are mainly used to send error codes.
func (*Response) Writer ¶
func (r *Response) Writer() http.ResponseWriter
type Router ¶
type Router interface { ServeHTTP(ctx *HttpContext) ServerFile(path string, fileRoot string) RouterNode GET(path string, handle HttpHandle) RouterNode HEAD(path string, handle HttpHandle) RouterNode OPTIONS(path string, handle HttpHandle) RouterNode POST(path string, handle HttpHandle) RouterNode PUT(path string, handle HttpHandle) RouterNode PATCH(path string, handle HttpHandle) RouterNode DELETE(path string, handle HttpHandle) RouterNode HiJack(path string, handle HttpHandle) WebSocket(path string, handle HttpHandle) Any(path string, handle HttpHandle) RegisterRoute(routeMethod string, path string, handle HttpHandle) RouterNode RegisterHandler(name string, handler HttpHandle) GetHandler(name string) (HttpHandle, bool) MatchPath(ctx Context, routePath string) bool }
Router is the interface that wraps the router method.
type RouterHandle ¶
type RouterHandle func(ctx *HttpContext)
Handle is a function that can be registered to a route to handle HTTP requests. Like http.HandlerFunc, but has a third parameter for the values of wildcards (variables).
type RouterNode ¶
type RouterNode interface { Use(m ...Middleware) *Node Middlewares() []Middleware Node() *Node }
type UploadFile ¶
type UploadFile struct { File multipart.File Header *multipart.FileHeader // contains filtered or unexported fields }
func NewUploadFile ¶
func NewUploadFile(file multipart.File, header *multipart.FileHeader) *UploadFile
func (*UploadFile) FileName ¶
func (f *UploadFile) FileName() string
get upload file client-local name
type WebSocket ¶
func (*WebSocket) ReadMessage ¶
read message from websocket.conn
func (*WebSocket) SendMessage ¶
send message from websocket.conn