ghttp

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Jan 31, 2024 License: MIT Imports: 18 Imported by: 2

Documentation

Overview

Package ghttp is a generated GoMock package.

Index

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 AppendMultipartFormData(w *multipart.Writer, fieldName, fileName string, fileData []byte) (err error)

func CheckRequestErr

func CheckRequestErr(fullurl string, status int, respBody []byte, err error) bool

CheckRESTErr print error with stack context and return true for error else false.

func ReadBody added in v0.0.9

func ReadBody(httpRs *http.Response) (rs []byte, err error)

read body data from http.Response, it allows call multiple times

func UseImpl added in v0.0.9

func UseImpl(impl HttpClient)

Types

type HttpClient added in v0.0.9

type HttpClient interface {
	Do(rq *http.Request) (rs *http.Response, err error)
}
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) Do added in v0.0.9

func (it *HttpRequest) Do(rq *http.Request) (rs *http.Response, err error)

Do implements HttpClient

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) Do added in v0.0.9

func (m *MockHttpClient) Do(rq *http.Request) (*http.Response, error)

Do mocks base method.

func (*MockHttpClient) EXPECT added in v0.0.9

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.

Jump to

Keyboard shortcuts

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