dhttp

package
v0.0.0-...-16de10f Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 27, 2018 License: MIT Imports: 9 Imported by: 12

README

DHTTP

Describe your http client / server

Middlewares

Check middlewares and how to make middleware at Middlewares

Documentation

Index

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

type Request struct {
	*http.Request
	MiddlewareValues map[string]interface{}
}

Request inheritance of http.Request

func (*Request) GetRemoteIP

func (r *Request) GetRemoteIP() net.IP

GetRemoteIP get net.IP from Request.RemoteAddr

func (*Request) ReadAllBody

func (r *Request) ReadAllBody() []byte

ReadAllBody read all body in []byte

func (*Request) SetMiddlewareValue

func (r *Request) SetMiddlewareValue(name string, value interface{})

SetMiddlewareValue set middleware value

type Response

type Response struct {
	*http.Response
}

Response inheritance of http.Response

func (*Response) ReadAllBody

func (r *Response) ReadAllBody() []byte

ReadAllBody read all response body

type ResponseWriter

type ResponseWriter struct {
	StatusCode int
	Done       bool
	// contains filtered or unexported fields
}

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

func (*ResponseWriter) WriteText

func (rw *ResponseWriter) WriteText(s string) (int, error)

WriteText use string to Write

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) Default

func (r *Route) Default(f RouteHandlerFunc) *Route

Default default handler

func (*Route) GET

func (r *Route) GET(f RouteHandlerFunc) *Route

GET handle GET at this route

func (*Route) GetRoute

func (r *Route) GetRoute(path string) *Route

GetRoute get subroute by path. Return nil if not found.

func (*Route) GetSubSegment

func (r *Route) GetSubSegment(seg string) *Route

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) HasRoute

func (r *Route) HasRoute(path string) bool

HasRoute check subroute exist by path

func (*Route) HasSubSegment

func (r *Route) HasSubSegment(seg string) bool

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) POST

func (r *Route) POST(f RouteHandlerFunc) *Route

POST handle POST at this route

func (*Route) PUT

func (r *Route) PUT(f RouteHandlerFunc) *Route

PUT handle PUT at this route

func (*Route) Route

func (r *Route) Route(path string) *Route

Route get/create route under current route

func (*Route) SubSegment

func (r *Route) SubSegment(seg string) *Route

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

func (*Route) Use

func (r *Route) Use(mw *Middleware, paths ...string) *Route

Use use middleware. paths are prefixes for path matching. By default it match all.

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) DELETE

func (c *TypeClient) DELETE() *TypeClient

DELETE set method to DELETE

func (*TypeClient) Do

func (c *TypeClient) Do() (*Response, error)

Do do http request

func (*TypeClient) GET

func (c *TypeClient) GET() *TypeClient

GET set method to GET

func (*TypeClient) HEAD

func (c *TypeClient) HEAD() *TypeClient

HEAD set method to HEAD

func (*TypeClient) OPTIONS

func (c *TypeClient) OPTIONS() *TypeClient

OPTIONS set method to OPTIONS

func (*TypeClient) PATCH

func (c *TypeClient) PATCH() *TypeClient

PATCH set method to PATCH

func (*TypeClient) POST

func (c *TypeClient) POST() *TypeClient

POST set method to POST

func (*TypeClient) PUT

func (c *TypeClient) PUT() *TypeClient

PUT set method to PUT

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

func (*TypeClient) TRACE

func (c *TypeClient) TRACE() *TypeClient

TRACE set method to TRACE

type TypeServer

type TypeServer struct {
	ServeMux *http.ServeMux
	Addr     string
	// contains filtered or unexported fields
}

TypeServer http server function collections struct

func Server

func Server() *TypeServer

Server create new http server

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) Start

func (svr *TypeServer) Start() error

Start start server listening

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.

Directories

Path Synopsis
middlewares

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL