Documentation ¶
Index ¶
- type Middleware
- type MiddlewareFunc
- type Request
- type Response
- type ResponseWriter
- type Route
- func (r *Route) CONNECT(f RouteHandlerFunc) *Route
- func (r *Route) DELETE(f RouteHandlerFunc) *Route
- func (r *Route) Default(f RouteHandlerFunc) *Route
- func (r *Route) GET(f RouteHandlerFunc) *Route
- func (r *Route) GetRoute(path string) *Route
- func (r *Route) GetSubSegment(seg string) *Route
- func (r *Route) HEAD(f RouteHandlerFunc) *Route
- func (r *Route) HasRoute(path string) bool
- func (r *Route) HasSubSegment(seg string) bool
- func (r *Route) OPTIONS(f RouteHandlerFunc) *Route
- func (r *Route) PATCH(f RouteHandlerFunc) *Route
- func (r *Route) POST(f RouteHandlerFunc) *Route
- func (r *Route) PUT(f RouteHandlerFunc) *Route
- func (r *Route) Route(path string) *Route
- func (r *Route) SubSegment(seg string) *Route
- func (r *Route) TRACE(f RouteHandlerFunc) *Route
- func (r *Route) Use(mw *Middleware, paths ...string) *Route
- type RouteHandlerFunc
- type TypeClient
- func (c *TypeClient) CONNECT() *TypeClient
- func (c *TypeClient) DELETE() *TypeClient
- func (c *TypeClient) Do() (*Response, error)
- func (c *TypeClient) GET() *TypeClient
- func (c *TypeClient) HEAD() *TypeClient
- func (c *TypeClient) OPTIONS() *TypeClient
- func (c *TypeClient) PATCH() *TypeClient
- func (c *TypeClient) POST() *TypeClient
- func (c *TypeClient) PUT() *TypeClient
- func (c *TypeClient) SetBody(buf []byte) *TypeClient
- func (c *TypeClient) SetBodyReader(reader io.Reader) *TypeClient
- func (c *TypeClient) SetContentType(contentType string) *TypeClient
- func (c *TypeClient) SetHeader(key, value string) *TypeClient
- func (c *TypeClient) SetQuery(key, value string) *TypeClient
- func (c *TypeClient) SetTimeout(dur time.Duration) *TypeClient
- func (c *TypeClient) SetURL(urlString string) *TypeClient
- func (c *TypeClient) TRACE() *TypeClient
- type TypeServer
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Middleware ¶
type Middleware struct { Name string Config interface{} Handler MiddlewareFunc // contains filtered or unexported fields }
Middleware http server middleware
func (*Middleware) Rename ¶
func (mw *Middleware) Rename(name string)
Rename rename your middleware to avoid value overwriting
type MiddlewareFunc ¶
type MiddlewareFunc func(w *ResponseWriter, r *Request, config interface{}) interface{}
MiddlewareFunc middleware handler func
type Request ¶
Request inheritance of http.Request
func (*Request) GetRemoteIP ¶
GetRemoteIP get net.IP from Request.RemoteAddr
func (*Request) ReadAllBody ¶
ReadAllBody read all body in []byte
func (*Request) SetMiddlewareValue ¶
SetMiddlewareValue set middleware value
type Response ¶
Response inheritance of http.Response
func (*Response) ReadAllBody ¶
ReadAllBody read all response body
type ResponseWriter ¶
ResponseWriter wrapper of http.ResponseWriter
func (*ResponseWriter) Header ¶
func (rw *ResponseWriter) Header() http.Header
Header http.ResponseWriter Header
func (*ResponseWriter) Write ¶
func (rw *ResponseWriter) Write(b []byte) (int, error)
Write http.ResponseWriter Write
func (*ResponseWriter) WriteHeader ¶
func (rw *ResponseWriter) WriteHeader(statusCode int)
WriteHeader http.ResponseWriter WriteHeader
type Route ¶
type Route struct { // Path string Segment string SubRoutes map[string]*Route // contains filtered or unexported fields }
Route http server route function collections struct
func (*Route) CONNECT ¶
func (r *Route) CONNECT(f RouteHandlerFunc) *Route
CONNECT handle TRACE at this route
func (*Route) DELETE ¶
func (r *Route) DELETE(f RouteHandlerFunc) *Route
DELETE handle DELETE at this route
func (*Route) GetSubSegment ¶
GetSubSegment get subroute by segment. Return nil if not found.
func (*Route) HEAD ¶
func (r *Route) HEAD(f RouteHandlerFunc) *Route
HEAD handle TRACE at this route
func (*Route) HasSubSegment ¶
HasSubSegment check subroute exist by segment
func (*Route) OPTIONS ¶
func (r *Route) OPTIONS(f RouteHandlerFunc) *Route
OPTIONS handle OPTIONS at this route
func (*Route) PATCH ¶
func (r *Route) PATCH(f RouteHandlerFunc) *Route
PATCH handle PATCH at this route
func (*Route) SubSegment ¶
SubSegment get/create a segment subroute under current route
func (*Route) TRACE ¶
func (r *Route) TRACE(f RouteHandlerFunc) *Route
TRACE handle TRACE at this route
type RouteHandlerFunc ¶
type RouteHandlerFunc func(w *ResponseWriter, r *Request)
RouteHandlerFunc route handler func
type TypeClient ¶
type TypeClient struct { Request *http.Request Method string URL string ContentType string Body []byte BodyReader io.Reader Header map[string]string Query map[string]string Timeout time.Duration // contains filtered or unexported fields }
TypeClient http function collections struct
func Client ¶
func Client(input ...TypeClient) *TypeClient
Client get new Client, can be inited by TypeClient
func (*TypeClient) CONNECT ¶
func (c *TypeClient) CONNECT() *TypeClient
CONNECT set method to CONNECT
func (*TypeClient) OPTIONS ¶
func (c *TypeClient) OPTIONS() *TypeClient
OPTIONS set method to OPTIONS
func (*TypeClient) SetBody ¶
func (c *TypeClient) SetBody(buf []byte) *TypeClient
SetBody set http body by []byte
func (*TypeClient) SetBodyReader ¶
func (c *TypeClient) SetBodyReader(reader io.Reader) *TypeClient
SetBodyReader set http body by io.Reader
func (*TypeClient) SetContentType ¶
func (c *TypeClient) SetContentType(contentType string) *TypeClient
SetContentType set content-type header
func (*TypeClient) SetHeader ¶
func (c *TypeClient) SetHeader(key, value string) *TypeClient
SetHeader set one header key
func (*TypeClient) SetQuery ¶
func (c *TypeClient) SetQuery(key, value string) *TypeClient
SetQuery set one query key
func (*TypeClient) SetTimeout ¶
func (c *TypeClient) SetTimeout(dur time.Duration) *TypeClient
SetTimeout set timeout
func (*TypeClient) SetURL ¶
func (c *TypeClient) SetURL(urlString string) *TypeClient
SetURL set URL
type TypeServer ¶
type TypeServer struct { ServeMux *http.ServeMux Addr string // contains filtered or unexported fields }
TypeServer http server function collections struct
func (*TypeServer) ListenOn ¶
func (svr *TypeServer) ListenOn(addr string) *TypeServer
ListenOn addr that server will listen on
func (*TypeServer) Route ¶
func (svr *TypeServer) Route(path string) *Route
Route get route then config it
func (*TypeServer) Use ¶
func (svr *TypeServer) Use(mw *Middleware, paths ...string) *TypeServer
Use use middleware. paths are prefixes for path matching. By default it match all.