Documentation
¶
Index ¶
- type Connect
- type HttpClient
- func (p *HttpClient) BindAuthorizationChangeEvent(callback func(isClear bool))
- func (c *HttpClient) Delete(url string) *HttpClientRequest
- func (c *HttpClient) Get(url string) *HttpClientRequest
- func (p *HttpClient) IsSetAuthorization() bool
- func (c *HttpClient) Post(url string) *HttpClientRequest
- func (c *HttpClient) Put(url string) *HttpClientRequest
- func (c *HttpClient) SetBasicAuth(username string, password ...string) *HttpClient
- func (c *HttpClient) SetDigestAuth(username, password string) *HttpClient
- func (c *HttpClient) SetPrivateProtocolHead(opt PrivateProtocolHead) *HttpClient
- func (c *HttpClient) SetTimeout(readTimeout, writeTimeout time.Duration) *HttpClient
- type HttpClientAuth
- type HttpClientAuthType
- type HttpClientRequest
- func (r *HttpClientRequest) AddHeader(key, val string) *HttpClientRequest
- func (r *HttpClientRequest) AddQuery(key, val string) *HttpClientRequest
- func (r *HttpClientRequest) DecodeFormData(maxMemorySize int64) (*multipart.Form, *http.Response, error)
- func (r *HttpClientRequest) DecodeJSON(obj any) (*http.Response, error)
- func (r *HttpClientRequest) GetQuery() url.Values
- func (r *HttpClientRequest) Send() (*http.Response, error)
- func (r *HttpClientRequest) SetBody(body io.ReadCloser, bodySize int64) *HttpClientRequest
- func (r *HttpClientRequest) SetContentType(contentType string) *HttpClientRequest
- func (r *HttpClientRequest) SetHeader(key, val string) *HttpClientRequest
- func (r *HttpClientRequest) SetJSON(data any) *HttpClientRequest
- func (r *HttpClientRequest) SetQuery(key, val string) *HttpClientRequest
- type HttpServer
- type HttpServerRequest
- type HttpServerResponse
- func (w *HttpServerResponse) AddHeader(key, val string) *HttpServerResponse
- func (w *HttpServerResponse) Data(code int, data []byte) error
- func (w *HttpServerResponse) JSON(code int, obj any) error
- func (w *HttpServerResponse) SetContentType(contentType string) *HttpServerResponse
- func (w *HttpServerResponse) SetHeader(key, val string) *HttpServerResponse
- type PrivateProtocolHead
- func (p *PrivateProtocolHead) Clone() *PrivateProtocolHead
- func (p *PrivateProtocolHead) ReadRequestHead(reader io.Reader) error
- func (p *PrivateProtocolHead) ReadResponseHead(reader io.Reader) error
- func (p *PrivateProtocolHead) WriteRequestHead(writer io.Writer) error
- func (p *PrivateProtocolHead) WriteResponseHead(writer io.Writer) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Connect ¶
type Connect struct {
// contains filtered or unexported fields
}
Connect 连接实例
func (*Connect) LockHttpClient ¶
func (ci *Connect) LockHttpClient() *HttpClient
HttpClient 获取HTTP客户端
func (*Connect) LockHttpServer ¶
func (ci *Connect) LockHttpServer() *HttpServer
HttpServer 获取HTTP服务端
type HttpClient ¶
type HttpClient struct {
// contains filtered or unexported fields
}
HttpClient 基于Socket连接的HTTP客户端
func NewHttpClient ¶
func NewHttpClient(conn net.Conn) *HttpClient
NewHttpClient 创建基于Socket连接的HTTP客户端
func (*HttpClient) BindAuthorizationChangeEvent ¶ added in v0.0.2
func (p *HttpClient) BindAuthorizationChangeEvent(callback func(isClear bool))
BindAuthorizationChangeEvent 绑定认证信息修改事件
func (*HttpClient) Delete ¶
func (c *HttpClient) Delete(url string) *HttpClientRequest
Delete 封装Delete请求
func (*HttpClient) IsSetAuthorization ¶ added in v0.0.2
func (p *HttpClient) IsSetAuthorization() bool
IsSetAuthorization 是否已设置认证信息
func (*HttpClient) SetBasicAuth ¶
func (c *HttpClient) SetBasicAuth(username string, password ...string) *HttpClient
SetBasicAuth 设置Basic认证信息
func (*HttpClient) SetDigestAuth ¶
func (c *HttpClient) SetDigestAuth(username, password string) *HttpClient
SetDigestAuth 设置Digest认证信息
func (*HttpClient) SetPrivateProtocolHead ¶
func (c *HttpClient) SetPrivateProtocolHead(opt PrivateProtocolHead) *HttpClient
SetPrivateProtocolHead 设置私有协议头
func (*HttpClient) SetTimeout ¶
func (c *HttpClient) SetTimeout(readTimeout, writeTimeout time.Duration) *HttpClient
SetTimeout 设置请求响应超时时间
type HttpClientAuth ¶
type HttpClientAuth struct { Type HttpClientAuthType // 认证类型 Username string // Basic/Digest认证用户名 Password string // Basic/Digest认证密码 }
HttpClientAuth HTTP客户端认证信息
type HttpClientAuthType ¶
type HttpClientAuthType int
HttpClientAuthType HTTP客户端认证类型
const ( HttpClientAuthTypeNone HttpClientAuthType = iota // 无认证 HttpClientAuthTypeBasic // 认证类型:基本认证 HttpClientAuthTypeDigest // 认证类型:摘要认证 HttpClientAuthTypeOAuth // 认证类型:OAuth认证;TODO: 未实现 )
HTTP客户端认证类型美剧
type HttpClientRequest ¶
type HttpClientRequest struct {
// contains filtered or unexported fields
}
HttpClientRequest HTTP自定义客户端请求对象
func NewHttpClientRequest ¶
func NewHttpClientRequest(client *HttpClient, method, url string) *HttpClientRequest
NewHttpClientRequest 创建HTTP自定义客户端请求对象
func (*HttpClientRequest) AddHeader ¶
func (r *HttpClientRequest) AddHeader(key, val string) *HttpClientRequest
AddHeader 添加请求头
func (*HttpClientRequest) AddQuery ¶
func (r *HttpClientRequest) AddQuery(key, val string) *HttpClientRequest
AddQuery 添加Query请求参数
func (*HttpClientRequest) DecodeFormData ¶
func (r *HttpClientRequest) DecodeFormData(maxMemorySize int64) (*multipart.Form, *http.Response, error)
DecodeFormData 执行请求并解析响应为FormData(请不要重复关闭Response.Body)
@param maxMemorySize: 最大内存大小,单位为字节(建议不要超过20MB,超出为文件内容将会自动落盘到临时文件,不用担心文件接收不到)
func (*HttpClientRequest) DecodeJSON ¶
func (r *HttpClientRequest) DecodeJSON(obj any) (*http.Response, error)
DecodeJSON 执行请求并解析响应为JSON(请不要重复关闭Response.Body)
func (*HttpClientRequest) GetQuery ¶
func (r *HttpClientRequest) GetQuery() url.Values
GetQuery 获取Query请求参数
func (*HttpClientRequest) Send ¶
func (r *HttpClientRequest) Send() (*http.Response, error)
Send 执行请求(请主动关闭Response.Body)
func (*HttpClientRequest) SetBody ¶
func (r *HttpClientRequest) SetBody(body io.ReadCloser, bodySize int64) *HttpClientRequest
SetBody 设置请求体
func (*HttpClientRequest) SetContentType ¶
func (r *HttpClientRequest) SetContentType(contentType string) *HttpClientRequest
SetContentType 设置Content-Type请求头信息
func (*HttpClientRequest) SetHeader ¶
func (r *HttpClientRequest) SetHeader(key, val string) *HttpClientRequest
SetHeader 设置请求头
func (*HttpClientRequest) SetJSON ¶
func (r *HttpClientRequest) SetJSON(data any) *HttpClientRequest
SetJsonBody 设置JSON请求体
func (*HttpClientRequest) SetQuery ¶
func (r *HttpClientRequest) SetQuery(key, val string) *HttpClientRequest
SetQuery 设置Query请求参数
type HttpServer ¶
type HttpServer struct {
// contains filtered or unexported fields
}
HttpServer 基于Socket连接的HTTP服务端
func NewHttpServer ¶
func NewHttpServer(conn net.Conn) *HttpServer
NewHttpServer 创建基于Socket连接的HTTP服务端
func (*HttpServer) SetPrivateProtocolHead ¶
func (s *HttpServer) SetPrivateProtocolHead(opt PrivateProtocolHead) *HttpServer
SetPrivateProtocolHead 设置私有协议头
func (*HttpServer) SetReadTimeout ¶
func (s *HttpServer) SetReadTimeout(readTimeout, writeTimeout time.Duration) *HttpServer
SetReadTimeout 设置请求响应超时时间
type HttpServerRequest ¶
type HttpServerRequest struct {
// contains filtered or unexported fields
}
HttpServerRequest HTTP自定义服务端请求对象
func NewHttpServerRequest ¶
func NewHttpServerRequest(server *HttpServer) *HttpServerRequest
NewHttpServerRequest 创建HTTP自定义服务端请求对象
func (*HttpServerRequest) BindJSON ¶
func (r *HttpServerRequest) BindJSON(obj any) error
BindJSON 绑定JSON数据(请不要重复Close Body)
func (*HttpServerRequest) RawRequest ¶
func (r *HttpServerRequest) RawRequest() *http.Request
RawRequest 获取原始请求对象
type HttpServerResponse ¶
type HttpServerResponse struct {
// contains filtered or unexported fields
}
HttpServerResponse HTTP自定义服务端响应对象
func NewHttpServerResponse ¶
func NewHttpServerResponse(server *HttpServer) *HttpServerResponse
NewHttpServerResponse 创建HTTP自定义服务端响应对象
func (*HttpServerResponse) AddHeader ¶
func (w *HttpServerResponse) AddHeader(key, val string) *HttpServerResponse
AddHeader 添加响应头
func (*HttpServerResponse) Data ¶
func (w *HttpServerResponse) Data(code int, data []byte) error
Send 执行响应(请主动关闭Response.Body)
func (*HttpServerResponse) JSON ¶
func (w *HttpServerResponse) JSON(code int, obj any) error
JSON 执行响应并序列化响应为JSON
func (*HttpServerResponse) SetContentType ¶
func (w *HttpServerResponse) SetContentType(contentType string) *HttpServerResponse
SetContentType 设置Content-Type响应头信息
func (*HttpServerResponse) SetHeader ¶
func (w *HttpServerResponse) SetHeader(key, val string) *HttpServerResponse
SetHeader 设置响应头
type PrivateProtocolHead ¶
type PrivateProtocolHead struct { RequestHead []byte // 请求前的私有协议头 ResponseHead []byte // 响应前的私有协议头 Strict bool // 是否严格模式,严格模式下,私有协议头内容必须完全一致,否则只检查长度一致 }
PrivateProtocolHead HTTP客户端私有协议头
func (*PrivateProtocolHead) Clone ¶
func (p *PrivateProtocolHead) Clone() *PrivateProtocolHead
Clone 克隆
func (*PrivateProtocolHead) ReadRequestHead ¶
func (p *PrivateProtocolHead) ReadRequestHead(reader io.Reader) error
ReadRequestHead 读取请求前的私有协议头
func (*PrivateProtocolHead) ReadResponseHead ¶
func (p *PrivateProtocolHead) ReadResponseHead(reader io.Reader) error
ReadResponseHead 读取响应前的私有协议头
func (*PrivateProtocolHead) WriteRequestHead ¶
func (p *PrivateProtocolHead) WriteRequestHead(writer io.Writer) error
WriteRequestHead 写入请求前的私有协议头
func (*PrivateProtocolHead) WriteResponseHead ¶
func (p *PrivateProtocolHead) WriteResponseHead(writer io.Writer) error
WriteResponseHead 写入响应前的私有协议头