Skip to content

GolangToolKits/go-http-proxy

Repository files navigation

go-http-proxy

A mockable http proxy

Go Report Card

Use Info

type Gresp struct{
    Status bool
    Message string
}
req, rErr := http.NewRequest("GET", "www.google.com/test", nil)

var resp Gresp
px := GoProxy{}
p := px.New()

callSuccess, httpStatusCode := p.Do(req, &resp)
// callSuccess indicates success of call
// httpStatusCode is status of the call
// resp contains the response---  make sure to pass a pointer

Use Info Mock

type Gresp struct{
    Status bool
    Message string
}
req, rErr := http.NewRequest("GET", "www.google.com/test", nil)

var w1 http.Response
	
w1.Body = ioutil.NopCloser(bytes.NewBufferString(`{"Status":true, "Message":"All good"}`))

var resp Gresp
px := MockGoProxy{}
px.MockDoSuccess1 = true
px.MockRespCode = 200
px.MockResp = &w1

p := px.New()

callSuccess, httpStatusCode := p.Do(req, &resp)
// callSuccess indicates success of call
// httpStatusCode is status of the call
// resp contains the response---  make sure to pass a pointer