Documentation ¶
Overview ¶
Package ghttp is a generated GoMock package.
Index ¶
- Constants
- Variables
- func AppendMultipartFormData(w *multipart.Writer, fieldName, fileName string, fileData []byte) (err error)
- func CheckRequestErr(fullurl string, status int, respBody []byte, err error) bool
- func ReadBody(httpRs *http.Response) (rs []byte, err error)
- func UseImpl(impl HttpClient)
- type HttpClient
- type HttpRequest
- func (it *HttpRequest) Do(rq *http.Request) (rs *http.Response, err error)
- func (it *HttpRequest) GenerateRequest() (rs *http.Request)
- func (it *HttpRequest) Send() (err error)
- func (it *HttpRequest) SetHeader(key string, value interface{}) *HttpRequest
- func (it *HttpRequest) SetHeaders(headers map[string]interface{}) *HttpRequest
- func (it *HttpRequest) SetHttpAuth(username, password string) *HttpRequest
- func (it *HttpRequest) SetPostBody(body []byte) *HttpRequest
- func (it *HttpRequest) SetProxy(addr string) *HttpRequest
- func (it *HttpRequest) SetRandomUserAgent(flag bool) *HttpRequest
- func (it *HttpRequest) SetRequestMethod(method string) *HttpRequest
- func (it *HttpRequest) SetTimeout(duration time.Duration) *HttpRequest
- func (it *HttpRequest) SetUri(uri string) *HttpRequest
- type MockHttpClient
- type MockHttpClientMockRecorder
Constants ¶
View Source
const ( HEAD = "HEAD" GET = "GET" POST = "POST" DELETE = "DELETE" )
Variables ¶
View Source
var (
UserAgents = []interface{}{
"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/42.0.2311.135 Safari/537.36 Edge/12.246",
"Mozilla/5.0 (iPhone14,6; U; CPU iPhone OS 15_4 like Mac OS X) AppleWebKit/602.1.50 (KHTML, like Gecko) Version/10.0 Mobile/19E241 Safari/602.1",
"Mozilla/5.0 (Linux; Android 13; SM-S901B) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/112.0.0.0 Mobile Safari/537.36",
"Mozilla/5.0 (Linux; Android 13; Pixel 6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/112.0.0.0 Mobile Safari/537.36",
}
)
Functions ¶
func AppendMultipartFormData ¶
func CheckRequestErr ¶
CheckRESTErr print error with stack context and return true for error else false.
func UseImpl ¶ added in v0.0.9
func UseImpl(impl HttpClient)
Types ¶
type HttpClient ¶ added in v0.0.9
var Client HttpClient
type HttpRequest ¶
type HttpRequest struct { Ctx context.Context Timeout time.Duration Method string Uri string Headers map[string]interface{} Body []byte UseRandomUserAgent bool UserAgent string Proxy string // request send at timestamp in unix(milliseconds) Rqts int64 Elapsed time.Duration // DEPRECATED. RespStatus int // DEPRECATED. RespBody []byte // DEPRECATED. RespHeader http.Header }
func New ¶
func New() *HttpRequest
func NewWithCtx ¶
func NewWithCtx(ctx context.Context) *HttpRequest
func (*HttpRequest) GenerateRequest ¶ added in v0.0.9
func (it *HttpRequest) GenerateRequest() (rs *http.Request)
func (*HttpRequest) Send ¶
func (it *HttpRequest) Send() (err error)
DEPRECATED.
`Send()` does not supports gomock, use `Do()` instead.
func (*HttpRequest) SetHeader ¶
func (it *HttpRequest) SetHeader(key string, value interface{}) *HttpRequest
func (*HttpRequest) SetHeaders ¶
func (it *HttpRequest) SetHeaders(headers map[string]interface{}) *HttpRequest
func (*HttpRequest) SetHttpAuth ¶
func (it *HttpRequest) SetHttpAuth(username, password string) *HttpRequest
func (*HttpRequest) SetPostBody ¶
func (it *HttpRequest) SetPostBody(body []byte) *HttpRequest
func (*HttpRequest) SetProxy ¶
func (it *HttpRequest) SetProxy(addr string) *HttpRequest
func (*HttpRequest) SetRandomUserAgent ¶
func (it *HttpRequest) SetRandomUserAgent(flag bool) *HttpRequest
func (*HttpRequest) SetRequestMethod ¶
func (it *HttpRequest) SetRequestMethod(method string) *HttpRequest
func (*HttpRequest) SetTimeout ¶
func (it *HttpRequest) SetTimeout(duration time.Duration) *HttpRequest
func (*HttpRequest) SetUri ¶
func (it *HttpRequest) SetUri(uri string) *HttpRequest
type MockHttpClient ¶ added in v0.0.9
type MockHttpClient struct {
// contains filtered or unexported fields
}
MockHttpClient is a mock of HttpClient interface.
func NewMockHttpClient ¶ added in v0.0.9
func NewMockHttpClient(ctrl *gomock.Controller) *MockHttpClient
NewMockHttpClient creates a new mock instance.
func (*MockHttpClient) EXPECT ¶ added in v0.0.9
func (m *MockHttpClient) EXPECT() *MockHttpClientMockRecorder
EXPECT returns an object that allows the caller to indicate expected use.
type MockHttpClientMockRecorder ¶ added in v0.0.9
type MockHttpClientMockRecorder struct {
// contains filtered or unexported fields
}
MockHttpClientMockRecorder is the mock recorder for MockHttpClient.
func (*MockHttpClientMockRecorder) Do ¶ added in v0.0.9
func (mr *MockHttpClientMockRecorder) Do(rq interface{}) *gomock.Call
Do indicates an expected call of Do.
Click to show internal directories.
Click to hide internal directories.