Created
February 19, 2014 01:21
-
-
Save rippinrobr/9084362 to your computer and use it in GitHub Desktop.
a slightly more advanced attr-server.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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