Documentation ¶
Index ¶
- Constants
- Variables
- func LoadConfig(configFile, configType string)
- func NewRoute(server *HttpServer) *route
- func NewView(s *HttpServer) *view
- type BaseMiddleware
- type Context
- type ExceptionHandle
- type Group
- type HijackConn
- type HttpContext
- func (ctx *HttpContext) CleanToken()
- func (ctx *HttpContext) CostTime() string
- func (ctx *HttpContext) End()
- func (ctx *HttpContext) GenerateSeesionToken(v jwt.MapClaims)
- func (ctx *HttpContext) GenerateToken(v jwt.MapClaims)
- func (ctx *HttpContext) Handler() HttpHandle
- func (ctx *HttpContext) Hijack() (*HijackConn, error)
- func (ctx *HttpContext) HttpServer() *HttpServer
- func (ctx *HttpContext) IsEnd() bool
- func (ctx *HttpContext) IsHijack() bool
- func (ctx *HttpContext) NotFound()
- func (ctx *HttpContext) QueryRouteParam(key string) string
- func (ctx *HttpContext) Redirect(url string, code int)
- func (ctx *HttpContext) RemoteIP() string
- func (ctx *HttpContext) RenderHtml(viewPath []string, locals map[string]interface{}) error
- func (ctx *HttpContext) Request() *Request
- func (ctx *HttpContext) Response() *Response
- func (ctx *HttpContext) RouteNode() RouteNode
- func (ctx *HttpContext) Store() *base.Store
- func (ctx *HttpContext) VerifyToken(v *map[string]interface{}) bool
- func (ctx *HttpContext) WriteBlob(contentType string, b []byte) (int, error)
- func (ctx *HttpContext) WriteBlobAndStatus(code int, contentType string, b []byte) (int, error)
- func (ctx *HttpContext) WriteHtml(content ...interface{}) (int, error)
- func (ctx *HttpContext) WriteHtmlAndStatus(status int, content ...interface{}) (int, error)
- func (ctx *HttpContext) WriteJSON(i interface{}) (int, error)
- func (ctx *HttpContext) WriteJSONAndStatus(status int, i interface{}) (int, error)
- func (ctx *HttpContext) WriteJSONBlob(b []byte) (int, error)
- func (ctx *HttpContext) WriteJSONBlobAndStatus(status int, b []byte) (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(content ...interface{}) (int, error)
- func (ctx *HttpContext) WriteStringAndStatus(status int, content ...interface{}) (int, error)
- type HttpHandle
- type HttpModule
- type HttpServer
- func (s *HttpServer) Group(prefix string) Group
- func (s *HttpServer) JwtConfig() *config.JwtNode
- func (s *HttpServer) ListenAndServe(addr string) error
- func (s *HttpServer) RegisterModule(module *HttpModule)
- func (s *HttpServer) Route() Router
- func (s *HttpServer) ServeHTTP(rw http.ResponseWriter, req *http.Request)
- func (s *HttpServer) ServerConfig() *config.ServerNode
- func (s *HttpServer) SetEnableDetailRequestData(enable bool)
- func (s *HttpServer) SetEnableIgnoreFavicon(enable bool)
- func (s *HttpServer) SetEnableJwt()
- func (s *HttpServer) SetJiaWeb(jiaweb *JiaWeb)
- func (s *HttpServer) TemplateConfig() *config.TemplateNode
- type JiaWeb
- func (app *JiaWeb) DefaultHTTPErrorHandler(ctx Context, err error)
- func (app *JiaWeb) DefaultMethodNotAllowedHandler(ctx Context)
- func (app *JiaWeb) DefaultNotFoundHandler(ctx Context)
- func (app *JiaWeb) IsDevelopmentMode() bool
- func (app *JiaWeb) ListenAndServe(addr string) error
- func (app *JiaWeb) RunMode() string
- func (app *JiaWeb) SetDevelopmentMode()
- func (app *JiaWeb) SetEnableDetailRequestData(enable bool)
- func (app *JiaWeb) SetEnableLog(enableLog bool)
- func (app *JiaWeb) SetExceptionHandle(handler ExceptionHandle)
- func (app *JiaWeb) SetLogPath(path string)
- func (app *JiaWeb) SetMethodNotAllowedHandle(handler StandardHandle)
- func (app *JiaWeb) SetNotFoundHandle(handler StandardHandle)
- func (app *JiaWeb) SetPProfConfig(enablePProf bool, port int)
- func (app *JiaWeb) SetProductionMode()
- func (app *JiaWeb) StartServer(port int) error
- func (app *JiaWeb) Use(m ...Middleware)
- func (app *JiaWeb) UseRequestLog()
- type KValue
- type LogJson
- type Middleware
- type MiddlewareFunc
- type Node
- type Param
- type Params
- type Request
- func (req *Request) Body() []byte
- func (req *Request) FormValues() map[string][]string
- func (req *Request) Get(key string) string
- func (req *Request) IsAJAX() bool
- func (req *Request) IsPost() bool
- func (req *Request) Path() string
- func (req *Request) Post(key string) string
- func (req *Request) RemoteIP() string
- func (req *Request) Url() string
- type RequestLogMiddleware
- type Response
- func (r *Response) Body() []byte
- func (r *Response) BodyString() string
- func (r *Response) Header() http.Header
- func (r *Response) Hijack() (net.Conn, *bufio.ReadWriter, error)
- func (r *Response) HttpStatus() int
- func (r *Response) QueryHeader(key string) string
- func (r *Response) Redirect(code int, targetUrl string) error
- func (r *Response) ResponseWriter() http.ResponseWriter
- func (r *Response) SetContentType(contentType string)
- func (r *Response) SetHeader(key, val string)
- func (r *Response) SetStatusCode(code int) error
- func (r *Response) Write(code int, b []byte) (n int, err error)
- func (r *Response) WriteHeader(code int) error
- type RouteHandle
- type RouteNode
- type Router
- type StandardHandle
- type Viewer
Constants ¶
View Source
const ( LogTarget_Default = "jiaweb_default" LogTarget_HttpRequest = "jiaweb_request" LogTarget_HttpServer = "jiaweb_server" LogLevel_Debug = "debug" LogLevel_Info = "info" LogLevel_Warn = "warn" LogLevel_Error = "error" )
Log define
View Source
const ( CharsetUTF8 = "text/plain; charset=utf-8" DefaultServerName = "jiaweb" )
Http define
View Source
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
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 ( DefaultHTTPPort = 8082 RunModeDevelopment = "development" RunModeProduction = "production" )
View Source
const ( HTTPMethod_Any = "ANY" HTTPMethod_GET = "GET" HTTPMethod_POST = "POST" HTTPMethod_PUT = "PUT" HTTPMethod_DELETE = "DELETE" HTTPMethod_PATCH = "PATCH" HTTPMethod_HiJack = "HIJACK" HTTPMethod_WebSocket = "WEBSOCKET" HTTPMethod_HEAD = "HEAD" HTTPMethod_OPTIONS = "OPTIONS" )
Variables ¶
View Source
var (
SupportHTTPMethod map[string]bool
)
Functions ¶
func LoadConfig ¶
func LoadConfig(configFile, configType string)
func NewRoute ¶
func NewRoute(server *HttpServer) *route
func NewView ¶
func NewView(s *HttpServer) *view
Types ¶
type BaseMiddleware ¶
type BaseMiddleware struct {
// contains filtered or unexported fields
}
func (*BaseMiddleware) Next ¶
func (bm *BaseMiddleware) Next(ctx Context) error
func (*BaseMiddleware) SetNext ¶
func (bm *BaseMiddleware) SetNext(m Middleware)
type Context ¶
type Context interface { HttpServer() *HttpServer Response() *Response Request() *Request Store() *base.Store RouteNode() RouteNode Handler() HttpHandle Hijack() (*HijackConn, error) RemoteIP() string IsHijack() bool End() NotFound() QueryRouteParam(key string) string RenderHtml(viewPath []string, locals map[string]interface{}) error WriteJSON(i interface{}) (int, error) WriteJSONAndStatus(status int, i interface{}) (int, error) WriteJSONBlob(b []byte) (int, error) WriteJSONBlobAndStatus(status int, b []byte) (int, error) WriteJSONP(callback string, i interface{}) (int, error) WriteJSONPBlob(callback string, b []byte) (size int, err error) WriteHtml(content ...interface{}) (int, error) WriteHtmlAndStatus(status int, content ...interface{}) (int, error) WriteString(content ...interface{}) (int, error) WriteStringAndStatus(status int, content ...interface{}) (int, error) WriteBlob(contentType string, b []byte) (int, error) WriteBlobAndStatus(status int, contentType string, b []byte) (int, error) GenerateToken(v jwt.MapClaims) CleanToken() GenerateSeesionToken(v jwt.MapClaims) CostTime() string VerifyToken(v *map[string]interface{}) bool Redirect(url string, code int) }
type Group ¶
type Group interface { Use(m ...Middleware) Group Group(prefix string, m ...Middleware) Group DELETE(path string, h HttpHandle) RouteNode GET(path string, h HttpHandle) RouteNode GETPOST(path string, h HttpHandle) HEAD(path string, h HttpHandle) RouteNode OPTIONS(path string, h HttpHandle) RouteNode PATCH(path string, h HttpHandle) RouteNode POST(path string, h HttpHandle) RouteNode PUT(path string, h HttpHandle) RouteNode RegisterRoute(method, path string, h HttpHandle) RouteNode }
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 }
func (*HijackConn) Close ¶
func (h *HijackConn) Close() error
func (*HijackConn) SetHedader ¶
func (h *HijackConn) SetHedader(key, value string)
func (*HijackConn) WriteString ¶
func (h *HijackConn) WriteString(content string) (int, error)
type HttpContext ¶
type HttpContext struct {
// contains filtered or unexported fields
}
func (*HttpContext) CleanToken ¶
func (ctx *HttpContext) CleanToken()
func (*HttpContext) CostTime ¶
func (ctx *HttpContext) CostTime() string
func (*HttpContext) End ¶
func (ctx *HttpContext) End()
func (*HttpContext) GenerateSeesionToken ¶
func (ctx *HttpContext) GenerateSeesionToken(v jwt.MapClaims)
func (*HttpContext) GenerateToken ¶
func (ctx *HttpContext) GenerateToken(v jwt.MapClaims)
func (*HttpContext) Handler ¶
func (ctx *HttpContext) Handler() HttpHandle
func (*HttpContext) Hijack ¶
func (ctx *HttpContext) Hijack() (*HijackConn, error)
func (*HttpContext) HttpServer ¶
func (ctx *HttpContext) HttpServer() *HttpServer
func (*HttpContext) IsEnd ¶
func (ctx *HttpContext) IsEnd() bool
func (*HttpContext) IsHijack ¶
func (ctx *HttpContext) IsHijack() bool
func (*HttpContext) NotFound ¶
func (ctx *HttpContext) NotFound()
func (*HttpContext) QueryRouteParam ¶
func (ctx *HttpContext) QueryRouteParam(key string) string
func (*HttpContext) Redirect ¶
func (ctx *HttpContext) Redirect(url string, code int)
func (*HttpContext) RemoteIP ¶
func (ctx *HttpContext) RemoteIP() string
func (*HttpContext) RenderHtml ¶
func (ctx *HttpContext) RenderHtml(viewPath []string, locals map[string]interface{}) error
func (*HttpContext) Request ¶
func (ctx *HttpContext) Request() *Request
func (*HttpContext) Response ¶
func (ctx *HttpContext) Response() *Response
func (*HttpContext) RouteNode ¶
func (ctx *HttpContext) RouteNode() RouteNode
func (*HttpContext) Store ¶
func (ctx *HttpContext) Store() *base.Store
func (*HttpContext) VerifyToken ¶
func (ctx *HttpContext) VerifyToken(v *map[string]interface{}) bool
func (*HttpContext) WriteBlob ¶
func (ctx *HttpContext) WriteBlob(contentType string, b []byte) (int, error)
func (*HttpContext) WriteBlobAndStatus ¶
func (*HttpContext) WriteHtml ¶
func (ctx *HttpContext) WriteHtml(content ...interface{}) (int, error)
func (*HttpContext) WriteHtmlAndStatus ¶
func (ctx *HttpContext) WriteHtmlAndStatus(status int, content ...interface{}) (int, error)
func (*HttpContext) WriteJSON ¶
func (ctx *HttpContext) WriteJSON(i interface{}) (int, error)
func (*HttpContext) WriteJSONAndStatus ¶
func (ctx *HttpContext) WriteJSONAndStatus(status int, i interface{}) (int, error)
func (*HttpContext) WriteJSONBlob ¶
func (ctx *HttpContext) WriteJSONBlob(b []byte) (int, error)
func (*HttpContext) WriteJSONBlobAndStatus ¶
func (ctx *HttpContext) WriteJSONBlobAndStatus(status int, b []byte) (int, error)
func (*HttpContext) WriteJSONP ¶
func (ctx *HttpContext) WriteJSONP(callback string, i interface{}) (int, error)
func (*HttpContext) WriteJSONPBlob ¶
func (ctx *HttpContext) WriteJSONPBlob(callback string, b []byte) (size int, err error)
func (*HttpContext) WriteString ¶
func (ctx *HttpContext) WriteString(content ...interface{}) (int, error)
func (*HttpContext) WriteStringAndStatus ¶
func (ctx *HttpContext) WriteStringAndStatus(status int, content ...interface{}) (int, error)
type HttpHandle ¶
type HttpModule ¶
type HttpServer ¶
type HttpServer struct { JiaWeb *JiaWeb Jwt *base.MJwt Modules []*HttpModule Render Viewer // contains filtered or unexported fields }
func NewHttpServer ¶
func NewHttpServer() *HttpServer
func (*HttpServer) Group ¶
func (s *HttpServer) Group(prefix string) Group
func (*HttpServer) JwtConfig ¶
func (s *HttpServer) JwtConfig() *config.JwtNode
func (*HttpServer) ListenAndServe ¶
func (s *HttpServer) ListenAndServe(addr string) error
func (*HttpServer) RegisterModule ¶
func (s *HttpServer) RegisterModule(module *HttpModule)
func (*HttpServer) Route ¶
func (s *HttpServer) Route() Router
func (*HttpServer) ServeHTTP ¶
func (s *HttpServer) ServeHTTP(rw http.ResponseWriter, req *http.Request)
func (*HttpServer) ServerConfig ¶
func (s *HttpServer) ServerConfig() *config.ServerNode
func (*HttpServer) SetEnableDetailRequestData ¶
func (s *HttpServer) SetEnableDetailRequestData(enable bool)
func (*HttpServer) SetEnableIgnoreFavicon ¶
func (s *HttpServer) SetEnableIgnoreFavicon(enable bool)
func (*HttpServer) SetEnableJwt ¶
func (s *HttpServer) SetEnableJwt()
func (*HttpServer) SetJiaWeb ¶
func (s *HttpServer) SetJiaWeb(jiaweb *JiaWeb)
func (*HttpServer) TemplateConfig ¶
func (s *HttpServer) TemplateConfig() *config.TemplateNode
type JiaWeb ¶
type JiaWeb struct { HttpServer *HttpServer Config *config.Config Logger logger.JiaLogger Middlewares []Middleware ExceptionHandler ExceptionHandle NotFoundHandler StandardHandle MethodNotAllowedHandler StandardHandle // contains filtered or unexported fields }
func (*JiaWeb) DefaultHTTPErrorHandler ¶
func (*JiaWeb) DefaultMethodNotAllowedHandler ¶
func (*JiaWeb) DefaultNotFoundHandler ¶
func (*JiaWeb) IsDevelopmentMode ¶
func (*JiaWeb) ListenAndServe ¶
func (*JiaWeb) SetDevelopmentMode ¶
func (app *JiaWeb) SetDevelopmentMode()
func (*JiaWeb) SetEnableDetailRequestData ¶
func (*JiaWeb) SetEnableLog ¶
func (*JiaWeb) SetExceptionHandle ¶
func (app *JiaWeb) SetExceptionHandle(handler ExceptionHandle)
func (*JiaWeb) SetLogPath ¶
func (*JiaWeb) SetMethodNotAllowedHandle ¶
func (app *JiaWeb) SetMethodNotAllowedHandle(handler StandardHandle)
func (*JiaWeb) SetNotFoundHandle ¶
func (app *JiaWeb) SetNotFoundHandle(handler StandardHandle)
func (*JiaWeb) SetPProfConfig ¶
func (*JiaWeb) SetProductionMode ¶
func (app *JiaWeb) SetProductionMode()
func (*JiaWeb) StartServer ¶
func (*JiaWeb) Use ¶
func (app *JiaWeb) Use(m ...Middleware)
func (*JiaWeb) UseRequestLog ¶
func (app *JiaWeb) UseRequestLog()
type Middleware ¶
type Middleware interface { Handle(ctx Context) error SetNext(m Middleware) Next(ctx Context) error }
type MiddlewareFunc ¶
type MiddlewareFunc func() Middleware
type Node ¶
type Node struct { Path string NodeType int Children []*Node Params Params // contains filtered or unexported fields }
func (*Node) Middleware ¶
func (n *Node) Middleware() []Middleware
func (*Node) Middlewares ¶
func (n *Node) Middlewares() []Middleware
type Request ¶
func (*Request) FormValues ¶
type RequestLogMiddleware ¶
type RequestLogMiddleware struct {
BaseMiddleware
}
func (*RequestLogMiddleware) Handle ¶
func (m *RequestLogMiddleware) Handle(ctx Context) error
type Response ¶
func NewResponse ¶
func NewResponse(rw http.ResponseWriter) (r *Response)
func (*Response) BodyString ¶
func (*Response) HttpStatus ¶
func (*Response) QueryHeader ¶
func (*Response) ResponseWriter ¶
func (r *Response) ResponseWriter() http.ResponseWriter
func (*Response) SetContentType ¶
func (*Response) SetStatusCode ¶
func (*Response) WriteHeader ¶
type RouteHandle ¶
type RouteHandle func(ctx *HttpContext)
type RouteNode ¶
type RouteNode interface { Use(m ...Middleware) *Node Middlewares() []Middleware Node() *Node }
type Router ¶
type Router interface { ServeHTTP(ctx *HttpContext) ServerFile(path, fileRoot string) RouteNode RegisterRoute(method string, path string, handle HttpHandle) RouteNode HEAD(path string, handle HttpHandle) RouteNode POST(path string, handle HttpHandle) RouteNode GETPOST(path string, handle HttpHandle) Any(path string, handle HttpHandle) GET(path string, handle HttpHandle) RouteNode PUT(path string, handle HttpHandle) RouteNode DELETE(path string, handle HttpHandle) RouteNode PATCH(path string, handle HttpHandle) RouteNode OPTIONS(path string, handle HttpHandle) RouteNode }
Middleware func(httpCtx *HttpContext)
type StandardHandle ¶
type StandardHandle func(Context)
Source Files ¶
Click to show internal directories.
Click to hide internal directories.