Skip to content

Instantly share code, notes, and snippets.

@marcosinger
Created December 10, 2015 15:46
Show Gist options
  • Save marcosinger/4d9614916eb18453c2bc to your computer and use it in GitHub Desktop.
Save marcosinger/4d9614916eb18453c2bc to your computer and use it in GitHub Desktop.
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