Created
December 10, 2015 15:46
-
-
Save marcosinger/4d9614916eb18453c2bc to your computer and use it in GitHub Desktop.
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 ( | |
"encoding/json" | |
"fmt" | |
"log" | |
"net/http" | |
) | |
func main() { | |
http.HandleFunc("/hardcoded", textHandle) | |
http.HandleFunc("/json_api", jsonHandle) | |
log.Fatal(http.ListenAndServe(":8080", nil)) | |
} | |
func textHandle(w http.ResponseWriter, r *http.Request) { | |
fmt.Fprintf(w, "foo") | |
} | |
func jsonHandle(w http.ResponseWriter, r *http.Request) { | |
j := struct { | |
Foo string `json:"foo"` | |
}{ | |
"bar", | |
} | |
json.NewEncoder(w).Encode(&j) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment