http_api

package
v0.0.0-...-e52ff56 Latest Latest
Warning

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

Go to latest
Published: May 31, 2017 License: MIT Imports: 18 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CompressHandler

func CompressHandler(h http.Handler) http.Handler

CompressHandler gzip compresses HTTP responses for clients that support it via the 'Accept-Encoding' header.

func Decorate

func Decorate(f APIHandler, ds ...Decorator) httprouter.Handle

以router.Handle("GET", "/ping", http_api.Decorate(s.pingHandler, log, http_api.PlainText))为例

func GetTopicChannelArgs

func GetTopicChannelArgs(rp getter) (string, string, error)

检验topic内容的正确性

func LogMethodNotAllowedHandler

func LogMethodNotAllowedHandler(l app.Logger) http.Handler

func LogNotFoundHandler

func LogNotFoundHandler(l app.Logger) http.Handler

func LogPanicHandler

func LogPanicHandler(l app.Logger) func(w http.ResponseWriter, req *http.Request, p interface{})

func NewDeadlineTransport

func NewDeadlineTransport(timeout time.Duration) *http.Transport

A custom http.Transport with support for deadline timeouts

func Respond

func Respond(w http.ResponseWriter, statusCode int, statusTxt string, data interface{})

根据后面的三个参数生成回复并发送出去

func RespondV1

func RespondV1(w http.ResponseWriter, code int, data interface{})

func Serve

func Serve(listener net.Listener, handler http.Handler, proto string, l app.Logger)

http服务器,主要参数是监听对象和handler

Types

type APIHandler

type APIHandler func(http.ResponseWriter, *http.Request, httprouter.Params) (interface{}, error)

函数对象定义

func NegotiateVersion

func NegotiateVersion(f APIHandler) APIHandler

func PlainText

func PlainText(f APIHandler) APIHandler

在f函数的基础之上增加了逻辑处理,返回新的函数

func V1

func V1(f APIHandler) APIHandler

type Client

type Client struct {
	// contains filtered or unexported fields
}

HTTP请求的客户端对象

func NewClient

func NewClient(tlsConfig *tls.Config) *Client

创建HTTP客户端对象

func (*Client) GETV1

func (c *Client) GETV1(endpoint string, v interface{}) error

GETV1 is a helper function to perform a V1 HTTP request and parse our NSQ daemon's expected response format, with deadlines.

func (*Client) NegotiateV1

func (c *Client) NegotiateV1(endpoint string, v interface{}) error

NegotiateV1 is a helper function to perform a v1 HTTP request and fallback to parsing the old backwards-compatible response format storing the result in the value pointed to by v.

TODO: deprecated, remove in 1.0 (replace calls with GETV1)

func (*Client) POSTV1

func (c *Client) POSTV1(endpoint string) error

PostV1 is a helper function to perform a V1 HTTP request and parse our NSQ daemon's expected response format, with deadlines.

type Decorator

type Decorator func(APIHandler) APIHandler

函数对象定义:入参和出参都是APIHandler 功能是对函数的二次包装,就是在原来函数的基层上面增加处理

func Log

func Log(l app.Logger) Decorator

log输出

type Err

type Err struct {
	Code int
	Text string
}

func (Err) Error

func (e Err) Error() string

type PostParams

type PostParams struct {
	*http.Request
}

出来Post方法的参数

func (*PostParams) Get

func (p *PostParams) Get(key string) (string, error)

type ReqParams

type ReqParams struct {
	url.Values        // 请求的消息头 map[string][]string
	Body       []byte // 请求的消息内容
}

请求参数对象

func NewReqParams

func NewReqParams(req *http.Request) (*ReqParams, error)

func (*ReqParams) Get

func (r *ReqParams) Get(key string) (string, error)

根据key获取value(第一个),因为消息头都是键值对

func (*ReqParams) GetAll

func (r *ReqParams) GetAll(key string) ([]string, error)

根据key获取value(全部),因为消息头都是键值对

Jump to

Keyboard shortcuts

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