Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@alt332
Last active October 25, 2015 11:00
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alt332/8d0a27a509a89ea298cf to your computer and use it in GitHub Desktop.
Save alt332/8d0a27a509a89ea298cf to your computer and use it in GitHub Desktop.
package main
import (
"net/http"
"encoding/json"
"io/ioutil"
"log"
"fmt"
)
type data []map[string]string
func returnJSON(w http.ResponseWriter, r *http.Request) {
jsonFile, _ := ioutil.ReadFile("./data.json")
var p data
fmt.Println("Starting")
_ = json.Unmarshal(jsonFile, &p)
w.Header().Set("Content-Type", "application/json")
w.Write(jsonFile)
}
func main() {
http.HandleFunc("/", returnJSON)
err := http.ListenAndServe(":9090", nil)
if err != nil {
log.Fatal("ListenAndServe: ", err)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment