Skip to content

Instantly share code, notes, and snippets.

@rippinrobr
Created February 19, 2014 01:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rippinrobr/9084362 to your computer and use it in GitHub Desktop.
Save rippinrobr/9084362 to your computer and use it in GitHub Desktop.
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
"github.com/codegangsta/martini"
)
// 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"
}
})
m.Run()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment