Documentation ¶
Index ¶
- Constants
- func CopyHttpRequest(r *http.Request) (*http.Request, error)
- func Error(w http.ResponseWriter, r *http.Request, err error)
- func FromFile(r *http.Request, name string) (*multipart.FileHeader, error)
- func GetClientIP(r *http.Request) string
- func GetExternalIP() (string, error)
- func GetInternalIP() string
- func GetQuery(r *http.Request, key string) (string, bool)
- func GetQueryArray(r *http.Request, key string) ([]string, bool)
- func GetTraceId(ctx context.Context) string
- func NewDefaultHTTPClient() *http.Client
- func NewHTTPClient(c *Config) *http.Client
- func OkJson(w http.ResponseWriter, r *http.Request, v interface{})
- func Params(params ...interface{}) interface{}
- func Parse(r *http.Request, v interface{}) error
- func ParseForm(r *http.Request, v interface{}) error
- func Query(r *http.Request, key string) string
- func QueryArray(r *http.Request, key string) []string
- func WriteHeader(w http.ResponseWriter, err ...error)
- type ChainReq
- type ChainResp
- type Client
- func (c *Client) Call(method, rawurl string, header map[string]string, data io.Reader, ...) error
- func (c *Client) CallChain(method, url string, header map[string]string, params, resp interface{}) error
- func (c *Client) CallWithRequest(req *http.Request, resp interface{}) (*http.Response, error)
- func (c *Client) GetRequest(method, rawurl string, header map[string]string, data io.Reader) (*http.Request, error)
- func (c *Client) GetResponse(req *http.Request) (*http.Response, []byte, error)
- type Config
- type DetailLoggedResponseWriter
- func (w *DetailLoggedResponseWriter) Flush()
- func (w *DetailLoggedResponseWriter) Header() http.Header
- func (w *DetailLoggedResponseWriter) Hijack() (net.Conn, *bufio.ReadWriter, error)
- func (w *DetailLoggedResponseWriter) Write(bs []byte) (int, error)
- func (w *DetailLoggedResponseWriter) WriteHeader(code int)
- type LoggedResponseWriter
- type RPCClient
- type RPCOption
- type RPCRequest
- type RPCResponse
- type Response
Constants ¶
const ( // MethodGet 请求方法:GET MethodGet = http.MethodGet // MethodHead 请求方法:HEAD MethodHead = http.MethodHead // MethodPost 请求方法:POST MethodPost = http.MethodPost // MethodPut 请求方法:PUT MethodPut = http.MethodPut // MethodPatch 请求方法:PATCH MethodPatch = http.MethodPatch // MethodDelete 请求方法:DELETE MethodDelete = http.MethodDelete // MethodConnect 请求方法:CONNECT MethodConnect = http.MethodConnect // MethodOptions 请求方法:OPTIONS MethodOptions = http.MethodOptions // MethodTrace 请求方法:TRACE MethodTrace = http.MethodTrace // HeaderAccept 请求头:Accept HeaderAccept = "Accept" // HeaderContentType 请求头:Content-Type HeaderContentType = "Content-Type" // HeaderDate 请求头:Date HeaderDate = "Date" // HeaderUserAgent 请求头:User-Agent HeaderUserAgent = "User-Agent" // HeaderAuthorization 请求头:Authorization HeaderAuthorization = "Authorization" // HeaderLocation 请求头:Location HeaderLocation = "Location" // HeaderContentDisposition 请求头:Content-Disposition HeaderContentDisposition = "Content-Disposition" // HeaderGWErrorCode 自定义网关请求头:X-GW-Error-Code HeaderGWErrorCode = "X-GW-Error-Code" // HeaderGWErrorMessage 自定义网关请求头:X-GW-Error-Message HeaderGWErrorMessage = "X-GW-Error-Message" // ApplicationForm 应用类型:x-www-form-urlencoded ApplicationForm = "application/x-www-form-urlencoded" // ApplicationStream 应用类型:octet-stream ApplicationStream = "application/octet-stream" // ApplicationJSON 应用类型:json ApplicationJSON = "application/json" // ApplicationXML 应用类型:xml ApplicationXML = "application/xml" // ApplicationText 应用类型:text ApplicationText = "application/text" // ApplicationZip 应用类型:zip ApplicationZip = "application/zip" )
Variables ¶
This section is empty.
Functions ¶
func CopyHttpRequest ¶
CopyHttpRequest 复制请求体
func GetQueryArray ¶
GetQueryArray 返回给定请求查询参数键的字符串切片值并判断其是否存在
func NewDefaultHTTPClient ¶
NewDefaultHTTPClient 新建默认HTTP客户端
func QueryArray ¶
QueryArray 返回给定请求查询参数键的字符串切片值
Types ¶
type ChainReq ¶
type ChainReq struct { Id int `json:"id"` Method string `json:"method"` Params interface{} `json:"params"` }
ChainReq 区块链HTTP调用请求
type ChainResp ¶
type ChainResp struct { Id int `json:"id"` Result json.RawMessage `json:"result"` Error string `json:"error"` }
ChainResp 区块链HTTP调用响应
type Client ¶
Client HTTP拓展客户端结构详情
func NewClientWithHTTPClient ¶
NewClientWithHTTPClient 使用HTTP客户端新建HTTP拓展客户端
func (*Client) Call ¶
func (c *Client) Call(method, rawurl string, header map[string]string, data io.Reader, resp interface{}) error
Call HTTP调用
func (*Client) CallChain ¶
func (c *Client) CallChain(method, url string, header map[string]string, params, resp interface{}) error
CallChain 区块链HTTP调用
func (*Client) CallWithRequest ¶
CallWithRequest 利用HTTP请求进行HTTP调用
type Config ¶
type Config struct { HTTPTimeout time.Duration // HTTP请求超时时间 DialTimeout time.Duration // 拨号超时时间 DialKeepAlive time.Duration // 拨号保持连接时间 MaxIdleConns int // 最大空闲连接数 MaxIdleConnsPerHost int // 每个主机最大空闲连接数 MaxConnsPerHost int // 每个主机最大连接数 IdleConnTimeout time.Duration // 空闲连接超时时间 ResponseHeaderTimeout time.Duration // 读取响应头超时时间 ExpectContinueTimeout time.Duration // 期望继续超时时间 TLSHandshakeTimeout time.Duration // TLS握手超时时间 ForceAttemptHTTP2 bool // 允许尝试启用HTTP/2 }
Config HTTP客户端相关配置
type DetailLoggedResponseWriter ¶
type DetailLoggedResponseWriter struct { Writer *LoggedResponseWriter Buf *bytes.Buffer }
DetailLoggedResponseWriter 详细日志记录响应写入器
func NewDetailLoggedResponseWriter ¶
func NewDetailLoggedResponseWriter(w http.ResponseWriter, r *http.Request) *DetailLoggedResponseWriter
NewDetailLoggedResponseWriter 新建详细日志记录响应写入器
func (*DetailLoggedResponseWriter) Flush ¶
func (w *DetailLoggedResponseWriter) Flush()
Flush 实现Flush方法
func (*DetailLoggedResponseWriter) Header ¶
func (w *DetailLoggedResponseWriter) Header() http.Header
Header 实现Header方法
func (*DetailLoggedResponseWriter) Hijack ¶
func (w *DetailLoggedResponseWriter) Hijack() (net.Conn, *bufio.ReadWriter, error)
Hijack 实现Hijack方法
func (*DetailLoggedResponseWriter) Write ¶
func (w *DetailLoggedResponseWriter) Write(bs []byte) (int, error)
Write 实现Write方法
func (*DetailLoggedResponseWriter) WriteHeader ¶
func (w *DetailLoggedResponseWriter) WriteHeader(code int)
WriteHeader 实现WriteHeader方法
type LoggedResponseWriter ¶
type LoggedResponseWriter struct { W http.ResponseWriter R *http.Request Code int }
LoggedResponseWriter 日志记录响应写入器
func NewLoggedResponseWriter ¶
func NewLoggedResponseWriter(w http.ResponseWriter, r *http.Request) *LoggedResponseWriter
NewLoggedResponseWriter 新建日志记录响应写入器
func (*LoggedResponseWriter) Header ¶
func (w *LoggedResponseWriter) Header() http.Header
Header 实现Header方法
func (*LoggedResponseWriter) Hijack ¶
func (w *LoggedResponseWriter) Hijack() (net.Conn, *bufio.ReadWriter, error)
Hijack 实现Hijack方法
func (*LoggedResponseWriter) Write ¶
func (w *LoggedResponseWriter) Write(bytes []byte) (int, error)
Write 实现Write方法
func (*LoggedResponseWriter) WriteHeader ¶
func (w *LoggedResponseWriter) WriteHeader(code int)
WriteHeader 实现WriteHeader方法
type RPCClient ¶
type RPCClient interface { // Call 进行 JSON-RPC 调用 Call(method string, params ...interface{}) (*RPCResponse, error) // CallRaw 基于所给请求体进行 JSON-RPC 调用 CallRaw(request *RPCRequest) (*RPCResponse, error) // CallFor 进行 JSON-RPC 调用并将响应结果反序列化到所给类型对象中 CallFor(out interface{}, method string, params ...interface{}) error }
RPCClient 通用 JSON-RPC 客户端接口
func NewRPCClient ¶
NewRPCClient 新建通用 JSON-RPC 客户端
type RPCOption ¶
type RPCOption func(server *rpcClient)
RPCOption JSON-RPC 客户端可选配置
func WithCustomHeaders ¶
WithCustomHeaders 使用配置的 HTTP 请求头
type RPCRequest ¶
type RPCRequest struct { JSONRPC string `json:"jsonrpc"` ID int `json:"id"` Method string `json:"method"` Params interface{} `json:"params,omitempty"` }
RPCRequest 通用 JSON-RPC 请求体
func NewRPCRequest ¶
func NewRPCRequest(method string, params ...interface{}) *RPCRequest
NewRPCRequest 新建通用 JSON-RPC 请求体
type RPCResponse ¶
type RPCResponse struct { JSONRPC string `json:"jsonrpc"` ID int `json:"id"` Result interface{} `json:"result,omitempty"` Error interface{} `json:"error,omitempty"` }
RPCResponse 通用 JSON-RPC 响应体
func (*RPCResponse) GetBool ¶
func (resp *RPCResponse) GetBool() (bool, error)
GetBool 获取响应结果的 bool 类型值
func (*RPCResponse) GetFloat64 ¶
func (resp *RPCResponse) GetFloat64() (float64, error)
GetFloat64 获取响应结果的 float64 类型值
func (*RPCResponse) GetInt64 ¶
func (resp *RPCResponse) GetInt64() (int64, error)
GetInt64 获取响应结果的 int64 类型值
func (*RPCResponse) GetString ¶
func (resp *RPCResponse) GetString() (string, error)
GetString 获取响应结果的 string 类型值
func (*RPCResponse) ReadToObject ¶
func (resp *RPCResponse) ReadToObject(to interface{}) error
ReadToObject 将响应结果反序列化到所给类型对象中
type Response ¶
type Response struct { TraceId string `json:"trace_id" example:"a1b2c3d4e5f6g7h8" extensions:"x-order=000"` // 链路追踪id Code uint32 `json:"code" example:"200" extensions:"x-order=001"` // 状态码 Msg string `json:"msg" example:"OK" extensions:"x-order=002"` // 消息 Data interface{} `json:"data" extensions:"x-order=003"` // 数据 }
Response 业务通用响应体