Created
November 21, 2013 19:20
-
-
Save jvoorhis/7587871 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 | |
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) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I didn't say it was useful...