In addition to the top answer, I found that in order for an answer to be perceived as a genuine customer article, it needs to be more fully formed. For a normal (200) answer, I do the following:
body := "Hello world" t := &http.Response{ Status: "200 OK", StatusCode: 200, Proto: "HTTP/1.1", ProtoMajor: 1, ProtoMinor: 1, Body: ioutil.NopCloser(bytes.NewBufferString(body)), ContentLength: int64(len(body)), Request: req, Header: make(http.Header, 0), }
Then you can, for example, add headers (with status code 401 to ask for authorization, say). req is the http.Request for which you are generating a response.
David g
source share