Created
May 7, 2015 13:51
-
-
Save albertoleal/0d238127d116d7d9471f to your computer and use it in GitHub Desktop.
Playing with go
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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