Documentation ¶
Index ¶
- Constants
- Variables
- func GetContentTypeCharset(contentType ContentType) string
- func NewRender(options *render.Options) *render.Render
- func RegisterListener(network string, ml MakeListener)
- func TLSConfigAutocert() (c *tls.Config, err error)
- func TLSConfigParse(certFile, keyFile interface{}) (TLSConfig *tls.Config, err error)
- func TLSConfigTransform(key, pem string) (c *tls.Config, err error)
- type Body
- type ContentType
- type Context
- func (c *Context) Abort()
- func (c *Context) Attachment(file, name string) error
- func (c *Context) Bind(i interface{}) error
- func (c *Context) Bytes(contentType ContentType, b []byte) (err error)
- func (c *Context) File(file string) (err error)
- func (c *Context) Flush()
- func (c *Context) Get(key string, dts ...RequestDataType) interface{}
- func (c *Context) GetFloat(key string, dts ...RequestDataType) (r float64)
- func (c *Context) GetInt(key string, dts ...RequestDataType) (r int)
- func (c *Context) GetInt32(key string, dts ...RequestDataType) (r int32)
- func (c *Context) GetInt64(key string, dts ...RequestDataType) (r int64)
- func (c *Context) GetString(key string, dts ...RequestDataType) (r string)
- func (c *Context) HTML(html string) (err error)
- func (c *Context) Header() http.Header
- func (c *Context) Hijack() (net.Conn, *bufio.ReadWriter, error)
- func (c *Context) Inline(file, name string) error
- func (c *Context) IsWebSocket() bool
- func (c *Context) JSON(i interface{}) error
- func (c *Context) JSONP(callback string, i interface{}) error
- func (c *Context) Protocol() string
- func (c *Context) Redirect(url string) error
- func (c *Context) RemoteAddr() string
- func (c *Context) Render(name string, data interface{}) (err error)
- func (c *Context) Route() string
- func (c *Context) Stream(contentType ContentType, r io.Reader) (err error)
- func (c *Context) String(s string) (err error)
- func (c *Context) Writable() bool
- func (c *Context) Write(b []byte) (n int, err error)
- func (c *Context) WriteHeader(code int)
- func (c *Context) XML(i interface{}, indent string) (err error)
- type Cookie
- type HTTPError
- type HTTPErrorHandler
- type Handler
- type HandlerCaller
- type HandlerFilter
- type HandlerFunc
- type HandlerSerialize
- type MakeListener
- type MiddlewareFunc
- type Next
- type Proxy
- type Render
- type RequestDataType
- type RequestDataTypeMap
- type Server
- func (srv *Server) Acquire(w http.ResponseWriter, r *http.Request) *Context
- func (srv *Server) Close() error
- func (srv *Server) DefaultHTTPErrorHandler(c *Context, err error)
- func (srv *Server) GET(path string, h HandlerFunc)
- func (srv *Server) Listen(ln net.Listener) (err error)
- func (srv *Server) POST(path string, h HandlerFunc)
- func (srv *Server) Proxy(prefix, address string, method ...string) *Proxy
- func (srv *Server) Register(route string, handler HandlerFunc, method ...string)
- func (srv *Server) Release(c *Context)
- func (srv *Server) ServeHTTP(w http.ResponseWriter, r *http.Request)
- func (srv *Server) Service(name string, handler ...interface{}) *registry.Service
- func (srv *Server) Start(address string, tlsConfig ...*tls.Config) (err error)
- func (srv *Server) Static(prefix, root string, method ...string) *Static
- func (srv *Server) Use(middleware ...MiddlewareFunc)
- type Static
Constants ¶
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 = "connect-Cookie" HeaderIfModifiedSince = "If-Modified-Since" HeaderLastModified = "Last-Modified" HeaderLocation = "Location" HeaderUpgrade = "Upgrade" HeaderVary = "Vary" HeaderWWWAuthenticate = "WWW-Authenticate" HeaderXForwardedFor = "X-Forwarded-For" HeaderXForwardedProto = "X-Forwarded-Code" HeaderXForwardedProtocol = "X-Forwarded-Protocol" HeaderXForwardedSsl = "X-Forwarded-Ssl" HeaderXUrlScheme = "X-Url-Protocol" HeaderXHTTPMethodOverride = "X-HTTP-value-Override" HeaderXRealIP = "X-Real-Addr" HeaderXRequestID = "X-Request-Index" HeaderXRequestedWith = "X-Requested-With" HeaderServer = "engine" HeaderOrigin = "origin" // Access control HeaderAccessControlRequestMethod = "Access-Control-Request-value" 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" // Security HeaderStrictTransportSecurity = "Strict-Transport-Security" HeaderXContentTypeOptions = "X-Content-Type-options" HeaderXXSSProtection = "X-XSS-Protection" HeaderXFrameOptions = "X-Frame-options" HeaderContentSecurityPolicy = "Content-Security-Policy" HeaderContentSecurityPolicyReportOnly = "Content-Security-Policy-Report-Only" HeaderXCSRFToken = "X-CSRF-Token" HeaderReferrerPolicy = "Referrer-Policy" )
Headers
const ( ContentTypeTextHTML ContentType = "text/html" ContentTypeTextPlain = "text/plain" ContentTypeTextXML = "text/xml" ContentTypeApplicationJS = "application/javascript" ContentTypeApplicationXML = "application/xml" ContentTypeApplicationJSON = "application/json" ContentTypeApplicationProtobuf = "application/protobuf" ContentTypeApplicationMsgpack = "application/msgpack" MIMEPROTOBUF = "application/x-protobuf" MIMEMSGPACKX = "application/x-msgpack" MIMEMSGPACK = "application/msgpack" ContentTypeOctetStream = "application/octet-stream" ContentTypeMultipartForm = "multipart/form-store" ContentTypeApplicationForm = "application/x-www-form-urlencoded" )
MIME types
Variables ¶
var ( ErrUnsupportedMediaType = NewHTTPError(http.StatusUnsupportedMediaType) ErrNotFound = NewHTTPError(http.StatusNotFound, "404 page not found") ErrForbidden = NewHTTPError(http.StatusForbidden) ErrMethodNotAllowed = NewHTTPError(http.StatusMethodNotAllowed) ErrStatusRequestEntityTooLarge = NewHTTPError(http.StatusRequestEntityTooLarge) ErrTooManyRequests = NewHTTPError(http.StatusTooManyRequests) ErrBadRequest = NewHTTPError(http.StatusBadRequest) ErrBadGateway = NewHTTPError(http.StatusBadGateway) ErrInternalServerError = NewHTTPError(http.StatusInternalServerError) ErrRequestTimeout = NewHTTPError(http.StatusRequestTimeout) ErrValidatorNotRegistered = errors.New("validator not registered") ErrRendererNotRegistered = errors.New("renderer not registered") ErrInvalidRedirectCode = errors.New("invalid redirect status code") ErrCookieNotFound = errors.New("cookie not found") ErrInvalidCertOrKeyType = errors.New("invalid cert or key type, must be string or []byte") ErrArgsNotFound = errors.New("args not found") ErrMimeTypeNotFound = errors.New("mime type not found") ErrHandlerError = errors.New("handler type error") )
Errors
var ( AnyHttpMethod = []string{ http.MethodGet, http.MethodHead, http.MethodPost, http.MethodPut, http.MethodPatch, http.MethodDelete, http.MethodConnect, http.MethodOptions, http.MethodTrace, } )
var Charset = "UTF-8"
Functions ¶
func GetContentTypeCharset ¶
func GetContentTypeCharset(contentType ContentType) string
GetContentTypeCharset
func RegisterListener ¶ added in v0.0.3
func RegisterListener(network string, ml MakeListener)
RegisterListener registers a MakeListener for network.
func TLSConfigAutocert ¶
createTLS starts an HTTPS server using certificates automatically installed from https://letsencrypt.org.
func TLSConfigParse ¶
通过文件或者证书内容获取TLSConfig
Types ¶
type ContentType ¶
type ContentType string
type Context ¶
type Context struct { Body *Body Binder binder.Interface Cookie *Cookie Session *session.Session Request *http.Request Response http.ResponseWriter // contains filtered or unexported fields }
Context API上下文.
func (*Context) Attachment ¶
Attachment 最终走File
func (*Context) Flush ¶
func (c *Context) Flush()
Flush implements the http.Flusher interface to allow an HTTP handler to flush buffered store to the client. See http.Flusher(https://golang.org/pkg/net/http/#Flusher)
func (*Context) Get ¶
func (c *Context) Get(key string, dts ...RequestDataType) interface{}
Get 获取参数,优先路径中的params 其他方式直接使用c.Request...
func (*Context) GetFloat ¶
func (c *Context) GetFloat(key string, dts ...RequestDataType) (r float64)
func (*Context) GetInt32 ¶ added in v0.1.0
func (c *Context) GetInt32(key string, dts ...RequestDataType) (r int32)
func (*Context) GetInt64 ¶ added in v0.1.0
func (c *Context) GetInt64(key string, dts ...RequestDataType) (r int64)
func (*Context) GetString ¶
func (c *Context) GetString(key string, dts ...RequestDataType) (r string)
func (*Context) Hijack ¶
Hijack implements the http.Hijacker interface to allow an HTTP handler to take over the connection. See http.Hijacker(https://golang.org/pkg/net/http/#Hijacker)
func (*Context) WriteHeader ¶
Status sends an HTTP Response header with status code. If Status is not called explicitly, the first call to Write will trigger an implicit Status(http.StatusOK). Thus explicit calls to Status are mainly used to send error codes.
type HTTPError ¶
type HTTPError struct { Code int `json:"-"` Message interface{} `json:"message"` }
HTTPError represents an error that occurred while handling a Request.
func NewHTTPError ¶
NewHTTPError creates a new HTTPError instance.
func NewHTTPError500 ¶
func NewHTTPError500(message interface{}) *HTTPError
type HTTPErrorHandler ¶
HTTPErrorHandler is a centralized HTTP error handler.
type Handler ¶ added in v0.0.3
type Handler struct {
// contains filtered or unexported fields
}
type HandlerCaller ¶ added in v0.0.3
type HandlerFilter ¶ added in v0.0.3
type HandlerFunc ¶
HandlerFunc defines a function to serve HTTP requests.
type HandlerSerialize ¶ added in v0.0.3
type MakeListener ¶ added in v0.0.3
MakeListener defines a listener generator.
func Listener ¶ added in v0.0.3
func Listener(network string) MakeListener
type MiddlewareFunc ¶
MiddlewareFunc defines a function to process middleware.
type Proxy ¶
type RequestDataType ¶
type RequestDataType int
const ( RequestDataTypeParam RequestDataType = iota //params RequestDataTypeBody //POST json, xml,pb,form.... RequestDataTypeQuery //GET RequestDataTypeCookie //COOKIES RequestDataTypeHeader //HEADER )
type RequestDataTypeMap ¶
type RequestDataTypeMap []RequestDataType
func (*RequestDataTypeMap) Add ¶
func (r *RequestDataTypeMap) Add(keys ...RequestDataType)
func (RequestDataTypeMap) IndexOf ¶
func (r RequestDataTypeMap) IndexOf(v RequestDataType) int
func (*RequestDataTypeMap) Reset ¶
func (r *RequestDataTypeMap) Reset(keys ...RequestDataType)
type Server ¶
type Server struct { SCC *scc.SCC Binder binder.Interface //默认序列化方式 Render Render Server *http.Server Router *registry.Router Registry *registry.Registry RequestDataType RequestDataTypeMap //使用GET获取数据时默认的查询方式 HTTPErrorHandler HTTPErrorHandler // contains filtered or unexported fields }
Server is the top-level framework instance.
func (*Server) Acquire ¶
Acquire returns an empty `Context` instance from the pool. You must return the Context by calling `ReleaseContext()`.
func (*Server) DefaultHTTPErrorHandler ¶
DefaultHTTPErrorHandler is the default HTTP error handler. It sends a JSON Response with status code.
func (*Server) GET ¶
func (srv *Server) GET(path string, h HandlerFunc)
GET registers a new GET Register for a path with matching handler in the Router with optional Register-level middleware.
func (*Server) POST ¶
func (srv *Server) POST(path string, h HandlerFunc)
POST registers a new POST Register for a path with matching handler in the Router with optional Register-level middleware.
func (*Server) Register ¶
func (srv *Server) Register(route string, handler HandlerFunc, method ...string)
Register AddTarget registers a new Register for an HTTP value and path with matching handler in the Router with optional Register-level middleware.
func (*Server) Release ¶
Release returns the `Context` instance back to the pool. You must call it after `AcquireContext()`.
func (*Server) ServeHTTP ¶
func (srv *Server) ServeHTTP(w http.ResponseWriter, r *http.Request)
ServeHTTP implements `http.Handler` interface, which serves HTTP requests.
func (*Server) Static ¶
Static registers a new Register with path prefix to serve static files from the provided root directory. 如果root 不是绝对路径 将以程序的WorkDir为根目录
func (*Server) Use ¶
func (srv *Server) Use(middleware ...MiddlewareFunc)
Use adds middleware to the chain which is run after Router.