Skip to content

Instantly share code, notes, and snippets.

@syguer
Created August 7, 2017 09:02
Show Gist options
  • Select an option

  • Save syguer/a182babd8b6d52f291ea6d2dfc5b3e75 to your computer and use it in GitHub Desktop.

Select an option

Save syguer/a182babd8b6d52f291ea6d2dfc5b3e75 to your computer and use it in GitHub Desktop.
package main
import (
"net/http"
"io/ioutil"
"encoding/json"
"log"
"strconv"
"fmt"
)
type HookReleaseObject struct {
HtmlUrl string `json:"html_url"`
TagName string `json:"tag_name"`
}
type HookObject struct {
Release HookReleaseObject `json:"release"`
}
type Server struct {
Port int
Server *http.Server
}
type Handler struct {}
func (h *Handler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
fmt.Println(r.Body)
body, _ := ioutil.ReadAll(r.Body)
o := HookObject{}
json.Unmarshal(body, &o)
fmt.Println(o)
}
func (s *Server) start() {
h := Handler{}
http.Handle("/", &h)
s.Server = &http.Server{
Addr: ":" + strconv.Itoa(s.Port),
Handler: &h,
}
log.Fatal(s.Server.ListenAndServe())
}
func main() {
s := Server{Port: 8080}
s.start()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment