Skip to content

Instantly share code, notes, and snippets.

@albertoleal
Created May 7, 2015 13:51
Show Gist options
  • Save albertoleal/0d238127d116d7d9471f to your computer and use it in GitHub Desktop.
Save albertoleal/0d238127d116d7d9471f to your computer and use it in GitHub Desktop.
Playing with go
package main
import (
"bytes"
"io"
"io/ioutil"
"net/http"
)
func handler(w http.ResponseWriter, r *http.Request) {
foo(r)
}
func main() {
http.HandleFunc("/", handler)
http.ListenAndServe(":8080", nil)
}
func foo(r *http.Request) *http.Response {
out := "{}"
var closerBuffer io.ReadCloser = ioutil.NopCloser(bytes.NewBufferString(out))
w := &http.Response{
Request: r,
StatusCode: http.StatusOK,
ProtoMajor: r.ProtoMajor,
ProtoMinor: r.ProtoMinor,
ContentLength: int64(len(out)),
Body: closerBuffer,
}
w.Header = make(map[string][]string)
w.Header.Add("Content-Type", "application/json")
return w
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment