Skip to content

Instantly share code, notes, and snippets.

Created October 2, 2014 04:32
Show Gist options
  • Save anonymous/b43c83d2dbbf2e925782 to your computer and use it in GitHub Desktop.
Save anonymous/b43c83d2dbbf2e925782 to your computer and use it in GitHub Desktop.
gistcli - Paste
package main
import (
"github.com/gin-gonic/gin"
"fmt"
)
type GithubUser struct {
Name string `json:name`
Email string `json:email`
Username string `json:username`
}
type GithubCommit struct {
Id string `json:id`
Message string `json:message`
Author GithubUser `json:author`
Committer GithubUser `json:committer`
}
type EventPush struct {
Ref string `json:ref`
After string `json:after`
Before string `json:before`
Created bool `json:created`
Deleted bool `json:deleted`
Forced bool `json:forced`
HeadCommit GithubCommit `json:head_commit`
Pusher GithubUser `json:pusher`
}
func main () {
r := gin.Default()
r.GET("/", func(c *gin.Context) {
c.String(200, "Hello World!")
})
r.POST("/", func(c *gin.Context) {
event_type := c.Request.Header.Get("X-Github-Event")
fmt.Println(event_type)
switch event_type {
case "push":
PostEventHandler(c)
default:
c.String(500, "Event not implemented")
}
})
r.Run(":1440")
}
func PostEventHandler(c *gin.Context) {
var event EventPush
if c.Bind(&event) {
fmt.Println(event)
fmt.Printf("ref %s\n", event.Ref)
fmt.Printf("after %s\n", event.After)
fmt.Printf("before %s\n", event.Before)
fmt.Printf("hc:id %s\n", event.HeadCommit.Id)
fmt.Printf("hc:auth:name %s\n", event.HeadCommit.Author.Name)
}
c.String(200, "")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment