Skip to content
This repository was archived by the owner on Jul 19, 2019. It is now read-only.

Improve Go server #36

Merged
merged 1 commit into from
Mar 1, 2015
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions server.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,11 @@ func handleComments(w http.ResponseWriter, r *http.Request) {
return
}

w.Header().Set("Content-Type", "application/json")
io.Copy(w, bytes.NewReader(commentData))

case "GET":
w.Header().Set("Content-Type", "application/json")
// stream the contents of the file to the response
io.Copy(w, bytes.NewReader(commentData))

Expand All @@ -81,5 +85,6 @@ func handleComments(w http.ResponseWriter, r *http.Request) {
func main() {
http.HandleFunc("/comments.json", handleComments)
http.Handle("/", http.FileServer(http.Dir("./public")))
log.Println("Server started: http://localhost:3000")
log.Fatal(http.ListenAndServe(":3000", nil))
}