Documentation
¶
Index ¶
- Constants
- Variables
- func BytesToString(b []byte) string
- func LogCreator() *logger
- func StringToBytes(s string) (b []byte)
- type BindUnmarshaler
- type Binder
- type Context
- type Core
- func (r Core) DELETE(path string, handler UserFunc)
- func (r Core) GET(path string, handler UserFunc)
- func (r Core) Group(prefix string, handlers ...HandlerFunc) *router
- func (r Core) HEAD(path string, handler UserFunc)
- func (r Core) OPTIONS(path string, handler UserFunc)
- func (r Core) PATCH(path string, handler UserFunc)
- func (r Core) POST(path string, handler UserFunc)
- func (r Core) PUT(path string, handler UserFunc)
- func (c *Core) ServeHTTP(w http.ResponseWriter, r *http.Request)
- func (c *Core) Start(addr string)
- func (r Core) Static(relativePath, root string)
- func (r Core) TRACE(path string, handler UserFunc)
- func (c *Core) Use(middleware ...HandlerFunc)
- type DefaultBinder
- type HTTPError
- type HandlerFunc
- type HandlersChain
- type Logger
- type Param
- type Params
- type ResponseWriter
- type UserFunc
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 = "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" // Access control 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" // 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" )
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
const ( Critical = iota Error Warning Trace Info Debug )
const Version = "Yee v0.0.1"
Variables ¶
var ( ErrUnsupportedMediaType = NewHTTPError(http.StatusUnsupportedMediaType) ErrNotFound = NewHTTPError(http.StatusNotFound) 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") )
Functions ¶
func BytesToString ¶
BytesToString converts byte slice to string without a memory allocation.
func LogCreator ¶
func LogCreator() *logger
func StringToBytes ¶
StringToBytes converts string to byte slice without a memory allocation.
Types ¶
type BindUnmarshaler ¶
type BindUnmarshaler interface {
// UnmarshalParam decodes and assigns a value from an form or query param.
UnmarshalParam(param string) error
}
BindUnmarshaler is the interface used to wrap the UnmarshalParam method. Types that don't implement this, but do implement encoding.TextUnmarshaler will use that interface instead.
type Context ¶
type Context interface {
Request() *http.Request
Response() ResponseWriter
HTML(code int, html string) (err error)
JSON(code int, i interface{}) error
String(code int, s string) error
Status(code int)
QueryParam(name string) string
QueryString() string
SetHeader(key string, value string)
AddHeader(key string, value string)
GetHeader(key string) string
FormValue(name string) string
FormParams() (url.Values, error)
FormFile(name string) (*multipart.FileHeader, error)
MultipartForm() (*multipart.Form, error)
Redirect(code int, uri string) error
Params(name string) string
RequestURI() string
Scheme() string
IsTls() bool
Next()
HTMLTml(code int, tml string) (err error)
QueryParams() map[string][]string
Bind(i interface{}) error
Get(key string) interface{}
Put(key string, values interface{})
ServerError(code int, defaultMessage []byte, IsMiddleware bool)
RemoteIp() string
Logger() Logger
Reset()
}
type Core ¶
type Core struct {
HandleMethodNotAllowed bool
RedirectTrailingSlash bool
RedirectFixedPath bool
// contains filtered or unexported fields
}
Core implement httpServer interface
func (Core) Group ¶
func (r Core) Group(prefix string, handlers ...HandlerFunc) *router
func (*Core) ServeHTTP ¶
func (c *Core) ServeHTTP(w http.ResponseWriter, r *http.Request)
override Handler.ServeHTTP all requests/response deal with here we use sync.pool save context variable because we do this can be used less memory we just only reset context, when before callback c.handleHTTPRequest func and put context variable into poll
func (*Core) Use ¶
func (c *Core) Use(middleware ...HandlerFunc)
type DefaultBinder ¶
type DefaultBinder struct{}
DefaultBinder is the default implementation of the Binder interface.
type HTTPError ¶
type HTTPError struct {
Code int
Message interface{}
Internal error // Stores the error returned by an external dependency
}
func NewHTTPError ¶
NewHTTPError creates a new HTTPError instance.
type HandlerFunc ¶
type HandlersChain ¶
type HandlersChain []HandlerFunc
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 ResponseWriter ¶
type ResponseWriter interface {
http.ResponseWriter
http.Hijacker
http.Flusher
http.CloseNotifier
// Returns the HTTP response status code of the current request.
Status() int
// Returns the number of bytes already written into the response http body.
// See Written()
Size() int
// Writes the string into the response body.
WriteString(string) (int, error)
// Returns true if the response body was already written.
Written() bool
//// Forces to write the http header (status code + headers).
WriteHeaderNow()
// get the http.Pusher for server push
Pusher() http.Pusher
Writer() http.ResponseWriter
Override(rw http.ResponseWriter)
}
ResponseWriter ...