Created
December 21, 2015 09:38
-
-
Save LeKovr/9b079a413e429758e53d to your computer and use it in GitHub Desktop.
Hook response parsing example
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 | |
/* | |
hookex.go - Hook response parsing example | |
Use: | |
echo '{"output":"Hook start\nProcessing event (push)\nError fired by secret\n","error":"exit status 1"}' | go run hookex.go | |
*/ | |
import ( | |
"encoding/json" | |
"fmt" | |
"io/ioutil" | |
"os" | |
) | |
func main() { | |
bytes, err := ioutil.ReadAll(os.Stdin) | |
checkErr(err) | |
mapData := make(map[string]interface{}) | |
err = json.Unmarshal(bytes, &mapData) | |
checkErr(err) | |
if out, ok := mapData["output"]; ok { | |
delete(mapData, "output") | |
fmt.Println("*** Output:\n", out) | |
} | |
data, err := json.MarshalIndent(mapData, "", " ") | |
checkErr(err) | |
fmt.Println("*** Payload:\n", string(data)) | |
} | |
func checkErr(err error) { | |
if err != nil { | |
panic(err.Error()) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment