Documentation ¶
Index ¶
- Constants
- Variables
- func BytesToString(b []byte) string
- func GenQueryExpr(QueryExpr []expr) (string, string, string)
- func GenerateRestfulAPI(GenCodeVal GenCodeVal) string
- func LogCreator() *logger
- func StringToBytes(s string) (b []byte)
- type BindUnmarshaler
- type Context
- type Core
- func (c *Core) NewContext(r *http.Request, w http.ResponseWriter) Context
- func (c *Core) Run(addr string)
- func (c *Core) RunH2C(addr string)
- func (c *Core) RunTLS(addr, certFile, keyFile string)
- func (c *Core) ServeHTTP(w http.ResponseWriter, r *http.Request)
- func (c *Core) SetLogLevel(l uint8)
- func (c *Core) Use(middleware ...HandlerFunc)
- type DefaultBinder
- type GenCodeVal
- type HandlerFunc
- type HandlersChain
- type Logger
- type Param
- type Params
- type ResponseWriter
- type RestfulAPI
- type Router
- func (r *Router) Any(path string, handler ...HandlerFunc)
- func (r *Router) DELETE(path string, handler ...HandlerFunc)
- func (r *Router) GET(path string, handler ...HandlerFunc)
- func (r *Router) Group(prefix string, handlers ...HandlerFunc) *Router
- func (r *Router) HEAD(path string, handler ...HandlerFunc)
- func (r *Router) OPTIONS(path string, handler ...HandlerFunc)
- func (r *Router) PATCH(path string, handler ...HandlerFunc)
- func (r *Router) POST(path string, handler ...HandlerFunc)
- func (r *Router) PUT(path string, handler ...HandlerFunc)
- func (r *Router) Packr(relativePath string, fs http.FileSystem)
- func (r *Router) Restful(path string, api RestfulAPI)
- func (r *Router) Static(relativePath, root string)
- func (r *Router) TRACE(path string, handler ...HandlerFunc)
- func (r *Router) Use(middleware ...HandlerFunc)
Constants ¶
const ( HeaderAccept = "Accept" HeaderAcceptEncoding = "Accept-Encoding" 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" HeaderReferrerPolicy = "Referrer-Policy" )
Header types
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 Info Debug )
logger types
const PREFIX = `` /* 815-byte string literal not displayed */
Variables ¶
var ( ErrUnsupportedMediaType = errors.New("http server not support media type") 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") ErrNotFoundHandler = errors.New("404 NOT FOUND") ErrInvalidCertOrKeyType = errors.New("invalid cert or key type, must be string or []byte") )
Err types
var FinderPrefix = `
type FinderPrefix struct {
Valve bool // 自行添加tag
${FINDER_EXPR}
}
`
var QueryExprPrefix = `` /* 150-byte string literal not displayed */
Functions ¶
func BytesToString ¶
BytesToString converts byte slice to string without a memory allocation.
func GenQueryExpr ¶
func GenerateRestfulAPI ¶
func GenerateRestfulAPI(GenCodeVal GenCodeVal) string
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) File(file string) 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 Cookie(name string) (*http.Cookie, error) SetCookie(cookie *http.Cookie) Cookies() []*http.Cookie Get(key string) interface{} Put(key string, values interface{}) ServerError(code int, defaultMessage string) error RemoteIP() string Logger() Logger Reset() }
Context is the default implementation interface of context
type Core ¶
type Core struct { *Router HandleMethodNotAllowed bool H2server *http.Server RedirectTrailingSlash bool RedirectFixedPath bool Banner bool // contains filtered or unexported fields }
Core implement httpServer interface
func NewAndSetBasePath ¶
func (*Core) NewContext ¶
NewContext is for testing
func (*Core) RunH2C ¶
RunH2C is launch of h2c In normal conditions, http2 must used certificate H2C is non-certificate`s http2 notes: 1.the browser is not supports H2C proto, you should write your web client test program 2.the H2C protocol is not safety
func (*Core) RunTLS ¶
RunTLS is launch of tls golang supports http2,if client supports http2 Otherwise, the http protocol return to http1.1
func (*Core) Use ¶
func (c *Core) Use(middleware ...HandlerFunc)
Use defines which middleware is uesd when we dose not match prefix or method we`ll register noRoute or noMethod handle for this otherwise, we cannot be verified for noRoute/noMethod
type DefaultBinder ¶
type DefaultBinder struct{}
DefaultBinder is the default implementation of the Binder interface.
func (*DefaultBinder) Bind ¶
func (b *DefaultBinder) Bind(i interface{}, c Context) (err error)
Bind implements the `Binder#Bind` function.
type GenCodeVal ¶
type Logger ¶
type Logger interface { Critical(msg string) Error(msg string) Warn(msg string) Info(msg string) Debug(msg string) SetLevel(level uint8) }
Logger ...
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 ...
type RestfulAPI ¶
type RestfulAPI struct { Get HandlerFunc Post HandlerFunc Delete HandlerFunc Put HandlerFunc }
RestfulAPI is the default implementation of restfulApi interface
type Router ¶
type Router struct {
// contains filtered or unexported fields
}
func (*Router) Any ¶
func (r *Router) Any(path string, handler ...HandlerFunc)
func (*Router) DELETE ¶
func (r *Router) DELETE(path string, handler ...HandlerFunc)
func (*Router) GET ¶
func (r *Router) GET(path string, handler ...HandlerFunc)
func (*Router) HEAD ¶
func (r *Router) HEAD(path string, handler ...HandlerFunc)
func (*Router) OPTIONS ¶
func (r *Router) OPTIONS(path string, handler ...HandlerFunc)
func (*Router) PATCH ¶
func (r *Router) PATCH(path string, handler ...HandlerFunc)
func (*Router) POST ¶
func (r *Router) POST(path string, handler ...HandlerFunc)
func (*Router) PUT ¶
func (r *Router) PUT(path string, handler ...HandlerFunc)
func (*Router) Restful ¶
func (r *Router) Restful(path string, api RestfulAPI)
func (*Router) TRACE ¶
func (r *Router) TRACE(path string, handler ...HandlerFunc)
func (*Router) Use ¶
func (r *Router) Use(middleware ...HandlerFunc)