Documentation ¶
Overview ¶
Package etp is a simple message dispatcher
ETP (Easy Transport Protocol) is copy from HTTP, support simple message route & dispatch.
contains:
- Request - Response - Route - Router
Index ¶
- Constants
- Variables
- func Error(w ResponseWriter, error string, code int)
- func NotFound(w ResponseWriter, r *Request)
- func ParseHTTPVersion(vers string) (major, minor int, ok bool)
- func StatusText(code int) string
- func WriteJSON(w ResponseWriter, code int, v interface{}) error
- type H
- type HandlerFunc
- type Request
- type Response
- type ResponseWriter
- type Route
- type Router
Constants ¶
View Source
const ( StatusContinue = 100 StatusSwitchingProtocols = 101 StatusOK = 200 StatusCreated = 201 StatusAccepted = 202 StatusNonAuthoritativeInfo = 203 StatusNoContent = 204 StatusResetContent = 205 StatusPartialContent = 206 StatusMultipleChoices = 300 StatusMovedPermanently = 301 StatusFound = 302 StatusSeeOther = 303 StatusNotModified = 304 StatusUseProxy = 305 StatusTemporaryRedirect = 307 StatusBadRequest = 400 StatusPaymentRequired = 402 StatusForbidden = 403 StatusNotFound = 404 StatusMethodNotAllowed = 405 StatusNotAcceptable = 406 StatusProxyAuthRequired = 407 StatusRequestTimeout = 408 StatusConflict = 409 StatusGone = 410 StatusLengthRequired = 411 StatusPreconditionFailed = 412 StatusRequestEntityTooLarge = 413 StatusRequestURITooLong = 414 StatusUnsupportedMediaType = 415 StatusRequestedRangeNotSatisfiable = 416 StatusExpectationFailed = 417 StatusTeapot = 418 StatusInternalServerError = 500 StatusNotImplemented = 501 StatusBadGateway = 502 StatusGatewayTimeout = 504 StatusHTTPVersionNotSupported = 505 )
HTTP status codes, defined in RFC 2616.
Variables ¶
Functions ¶
func Error ¶
func Error(w ResponseWriter, error string, code int)
Error replies to the request with the specified error message and HTTP code. The error message should be plain text.
func NotFound ¶
func NotFound(w ResponseWriter, r *Request)
NotFound replies to the request with an HTTP 404 not found error.
func ParseHTTPVersion ¶
ParseHTTPVersion parses a HTTP version string. "HTTP/1.0" returns (1, 0, true).
func StatusText ¶
StatusText returns a text for the HTTP status code. It returns the empty string if the code is unknown.
func WriteJSON ¶
func WriteJSON(w ResponseWriter, code int, v interface{}) error
Types ¶
type HandlerFunc ¶
type HandlerFunc func(ResponseWriter, *Request)
func (HandlerFunc) ServeETP ¶
func (f HandlerFunc) ServeETP(w ResponseWriter, r *Request)
ServeETP calls f(r)
type Request ¶
type Request struct { Method string URL *url.URL Proto string // "ETP/1.0" ProtoMajor int // 1 ProtoMinor int // 0 PathArgs []string QueryArgs map[string][]string // TODO: ExtHeader http.Header // 扩展头部 Header http.Header Body []byte ContentLength int64 // TODO: needed? RequestURI string }
func ReadRequest ¶
type Response ¶
type Response struct { Status string // e.g. "200 OK" StatusCode int // e.g. 200 Proto string // "ETP/1.0" ProtoMajor int // 1 ProtoMinor int // 0 PathArgs []string QueryArgs map[string][]string // TODO: Header http.Header Body []byte ContentLength int64 // TODO: needed? }
func ReadResponse ¶
type ResponseWriter ¶
type ResponseWriter interface { Header() http.Header Write([]byte) (int, error) WriteString(string) (int, error) WriteHeader(int) Bytes() []byte Status() int }
参考 http.ResponseWriter
func NewResponseWriter ¶
func NewResponseWriter() ResponseWriter
type Route ¶
type Route struct { Method string Pattern string Handler HandlerFunc }
Click to show internal directories.
Click to hide internal directories.