Change start implementation
This commit is contained in:
parent
8bdcd6d576
commit
8653bae6ac
|
@ -70,19 +70,19 @@ func (gh *GHWebhooks) Gather(acc inputs.Accumulator) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (gh *GHWebhooks) listen() error {
|
||||||
|
r := mux.NewRouter()
|
||||||
|
r.HandleFunc("/webhooks", gh.webhookHandler).Methods("POST")
|
||||||
|
http.ListenAndServe(fmt.Sprintf(":%s", gh.ServiceAddress), r)
|
||||||
|
}
|
||||||
|
|
||||||
func (gh *GHWebhooks) Start() error {
|
func (gh *GHWebhooks) Start() error {
|
||||||
gh.Lock()
|
gh.done = make(chan struct{})
|
||||||
defer gh.Unlock()
|
gh.in = make(chan mod.Event)
|
||||||
for {
|
// Start the UDP listener
|
||||||
select {
|
go gh.listen()
|
||||||
case <-gh.done:
|
// Start the line parser
|
||||||
return nil
|
log.Printf("Started the ghwebhooks service on %s\n", s.ServiceAddress)
|
||||||
default:
|
|
||||||
r := mux.NewRouter()
|
|
||||||
r.HandleFunc("/webhooks", gh.webhookHandler).Methods("POST")
|
|
||||||
http.ListenAndServe(fmt.Sprintf(":%s", gh.ServiceAddress), r)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (gh *GHWebhooks) Stop() {
|
func (gh *GHWebhooks) Stop() {
|
||||||
|
@ -95,6 +95,8 @@ func (gh *GHWebhooks) Stop() {
|
||||||
|
|
||||||
// Handles the /webhooks route
|
// Handles the /webhooks route
|
||||||
func (gh *GHWebhooks) webhookHandler(w http.ResponseWriter, r *http.Request) {
|
func (gh *GHWebhooks) webhookHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
|
gh.Lock()
|
||||||
|
defer gh.Unlock()
|
||||||
eventType := r.Header["X-Github-Event"][0]
|
eventType := r.Header["X-Github-Event"][0]
|
||||||
data, err := ioutil.ReadAll(r.Body)
|
data, err := ioutil.ReadAll(r.Body)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
Loading…
Reference in New Issue