Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
a slightly more advanced attr-server.go
package main
// loading in the Martini package
import (
"net/http" // this will allow us to use http.StatusOK and http.StatusNotFound instead of 200 and 404
"strings" // I’m adding this so I can ensure that we are comparing lower case strings
// defining the struct that I will use to create my error message that
// will be 'jsonified' and sent back to the caller. The `json:"msg"`
// tells the json encoder what name to use for this property in the json
// object
type ErrorMsg struct {
Msg string `json:"msg"`
func main() {
// := is a short variable declaration it types and instantiates the var 'on the fly'
m := martini.Classic()
m.Get("/attributes/:resource", func( params martini.Params ) (int, string) {
resource := strings.ToLower( params["resource"] )
if resource == "tv" {
return http.StatusOK, "a TV attributes object will be returned here"
} else {
return http.StatusNotFound, "JSON Object here"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment