Skip to content

Instantly share code, notes, and snippets.

@lucacervasio
Last active August 29, 2015 14:26
Show Gist options
  • Save lucacervasio/3b7bb0a17fe50cd27aba to your computer and use it in GitHub Desktop.
Save lucacervasio/3b7bb0a17fe50cd27aba to your computer and use it in GitHub Desktop.
package main
import (
"encoding/json"
"fmt"
)
type Envelope struct {
Token string `json:token`
Project string `json:project`
Type string `json:type`
Payload json.RawMessage `json:payload`
}
type Commit struct {
Author string `json:author`
Date string `json:date`
LinesAdd int `json:linesadd`
LinesDel int `json:linesdel`
Message string `json:message`
}
type PushMessage struct {
Repo string `json:repo`
Commits []Commit `json:commits`
}
func main() {
b := []byte(`{
"token": "iasydiajshdkjash87",
"project": "arasto",
"type": "push",
"payload":{"repo": "arasto3", "commits": [{"author": "dm", "date": "2015-08-07 15:14", "linesadd": 21, "linesdel": 15, "message": "blabla"},{"author": "dm", "date": "2015-08-08 16:14", "linesadd": 5, "linesdel": 3, "message": "msg2"}]}
}`)
var envelope Envelope
err := json.Unmarshal(b, &envelope)
if err != nil {
fmt.Println(err)
}
var pushata PushMessage
err = json.Unmarshal(envelope.Payload, &pushata)
if err != nil {
fmt.Println(err)
}
fmt.Println(pushata)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment