Skip to content

Instantly share code, notes, and snippets.

@eduardonunesp
Created September 3, 2015 17:16
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save eduardonunesp/0bdbecbfc0c43153fa45 to your computer and use it in GitHub Desktop.
Save eduardonunesp/0bdbecbfc0c43153fa45 to your computer and use it in GitHub Desktop.
package main
import (
"encoding/json"
"github.com/codegangsta/negroni"
"github.com/gorilla/mux"
"log"
"net/http"
"strconv"
)
const (
PORT int = 9000
HOST string = "localhost"
)
type Item struct {
Name string `json:"name"`
Done bool `json:"done"`
}
type List struct {
Name string `json:"name"`
Items []Item `json:"items"`
}
func main() {
log.Printf("Startup on %s:%d", HOST, PORT)
router := mux.NewRouter()
router.HandleFunc("/", func(w http.ResponseWriter, req *http.Request) {
list := &List{
"Todos", []Item{
{"Clean the house", false},
{"Feed the dog", false},
{"Check mailbox", false},
},
}
w.Header().Set("Content-Type", "application/json; charset=utf-8")
json.NewEncoder(w).Encode(list)
})
n := negroni.Classic()
n.UseHandler(router)
n.Run(HOST + ":" + strconv.Itoa(PORT))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment