Skip to content

Instantly share code, notes, and snippets.

@jvoorhis
Created November 21, 2013 19:20
Show Gist options
  • Save jvoorhis/7587871 to your computer and use it in GitHub Desktop.
Save jvoorhis/7587871 to your computer and use it in GitHub Desktop.
package main
import (
"encoding/json"
"fmt"
"net/http"
"io/ioutil"
)
type Deploy struct {
RefSpec string `json:"refspec"`
Environment string `json:"environment"`
User string `json:"user"`
}
func deployHandler(w http.ResponseWriter, r *http.Request) {
body, readErr := ioutil.ReadAll(r.Body)
if readErr != nil {
fmt.Println("I didn't get that.")
panic(readErr)
}
deploy := new(Deploy)
parseErr := json.Unmarshal(body, &deploy)
if parseErr != nil {
fmt.Println("It doesn't parse.")
panic(parseErr)
}
fmt.Printf("refspec:%v\n", deploy.RefSpec)
fmt.Printf("environment:%v\n", deploy.Environment)
fmt.Printf("user:%v\n", deploy.User)
}
func main() {
http.HandleFunc("/deploy", deployHandler)
http.ListenAndServe(":8080", nil)
}
@jvoorhis
Copy link
Author

I didn't say it was useful...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment