Documentation ¶
Index ¶
- func StringToBytes(s string) []byte
- func WriteJSON(w http.ResponseWriter, obj interface{}) error
- func WriteString(w http.ResponseWriter, format string, data []interface{}) (err error)
- type Context
- func (c *Context) Abort()
- func (c *Context) GetQuery(key string) (string, bool)
- func (c *Context) GetQueryArray(key string) ([]string, bool)
- func (c *Context) IsAborted() bool
- func (c *Context) JSON(code int, obj interface{})
- func (c *Context) Next()
- func (c *Context) Query(key string) string
- func (c *Context) Render(code int, r Render)
- func (c *Context) String(code int, format string, values ...interface{})
- type Engine
- type H
- type HandlersChain
- type IRouter
- type JSON
- type R
- type Render
- type ResponseWriter
- type Router
- func (group *Router) DELETE(relativePath string, handlers ...handler) IRouter
- func (group *Router) GET(relativePath string, handlers ...handler) IRouter
- func (group *Router) Group(relativePath string, handlers ...handler) *Router
- func (group *Router) HEAD(relativePath string, handlers ...handler) IRouter
- func (group *Router) OPTIONS(relativePath string, handlers ...handler) IRouter
- func (group *Router) PATCH(relativePath string, handlers ...handler) IRouter
- func (group *Router) POST(relativePath string, handlers ...handler) IRouter
- func (group *Router) PUT(relativePath string, handlers ...handler) IRouter
- func (group *Router) Use(middleware ...handler) IRouter
- type String
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func StringToBytes ¶
StringToBytes converts string to byte slice without a memory allocation.
func WriteJSON ¶
func WriteJSON(w http.ResponseWriter, obj interface{}) error
WriteJSON marshals the given interface object and writes it with custom ContentType.
func WriteString ¶
func WriteString(w http.ResponseWriter, format string, data []interface{}) (err error)
Types ¶
type Context ¶
type Context struct { Request *http.Request //ResponseWriter 包含了: // http.ResponseWriter,http.Hijacker,http.Flusher,http.CloseNotifier和额外方法 // 暴露给handler,是writermen的复制 Writer ResponseWriter // contains filtered or unexported fields }
封装Request、ResponseWriter
func (*Context) GetQueryArray ¶
GetQueryArray returns a slice of strings for a given query key, plus a boolean value whether at least one value exists for the given key.
func (*Context) Query ¶
Query returns the keyed url query value if it exists, otherwise it returns an empty string `("")`.
type HandlersChain ¶
type HandlersChain []handler
type IRouter ¶
type IRouter interface { Use(...handler) IRouter //Handle(string, string, ...handler) IRouter //Any(string, ...handler) IRouter GET(string, ...handler) IRouter POST(string, ...handler) IRouter DELETE(string, ...handler) IRouter PATCH(string, ...handler) IRouter PUT(string, ...handler) IRouter OPTIONS(string, ...handler) IRouter HEAD(string, ...handler) IRouter }
IRouter defines all router handle interface.
type JSON ¶
type JSON struct {
Data interface{}
}
func (JSON) Render ¶
func (r JSON) Render(w http.ResponseWriter) (err error)
Render (JSON) writes data with custom ContentType.
func (JSON) WriteContentType ¶
func (r JSON) WriteContentType(w http.ResponseWriter)
WriteContentType (JSON) writes JSON ContentType.
type R ¶
type R struct { http.ResponseWriter // contains filtered or unexported fields }
构建一个实现ResponseWriter的结构体类型
func (*R) CloseNotify ¶
func (*R) WriteHeaderNow ¶
func (r *R) WriteHeaderNow()
type Render ¶
type Render interface { // Render writes data with custom ContentType. Render(http.ResponseWriter) error // WriteContentType writes custom ContentType. WriteContentType(w http.ResponseWriter) }
Render接口被JSON、xml、html等实现后提供不同的ContentType内容
type ResponseWriter ¶
type ResponseWriter interface { http.ResponseWriter http.Hijacker http.Flusher http.CloseNotifier // get the http.Pusher for server push Pusher() http.Pusher // 强制写入http header(status code + headers). WriteHeaderNow() }
封装http.ResponseWriter接口,该接口在http中被实现response
type Router ¶
type Router struct { Handlers HandlersChain // contains filtered or unexported fields }
type String ¶
type String struct { Format string Data []interface{} }
func (String) WriteContentType ¶
func (r String) WriteContentType(w http.ResponseWriter)