@@ -2,8 +2,8 @@ package main
22
33import (
44 "fmt"
5-
65 "net/http"
6+ "time"
77
88 "github.com/go-playground/webhooks/v6/github"
99)
@@ -15,11 +15,12 @@ const (
1515func main () {
1616 hook , _ := github .New (github .Options .Secret ("MyGitHubSuperSecretSecrect...?" ))
1717
18- http .HandleFunc (path , func (w http.ResponseWriter , r * http.Request ) {
18+ mux := http .NewServeMux ()
19+ mux .HandleFunc (path , func (w http.ResponseWriter , r * http.Request ) {
1920 payload , err := hook .Parse (r , github .ReleaseEvent , github .PullRequestEvent )
2021 if err != nil {
2122 if err == github .ErrEventNotFound {
22- // ok event wasn; t one of the ones asked to be parsed
23+ // ok event wasn' t one of the ones asked to be parsed
2324 }
2425 }
2526 switch payload .(type ) {
@@ -35,5 +36,18 @@ func main() {
3536 fmt .Printf ("%+v" , pullRequest )
3637 }
3738 })
38- http .ListenAndServe (":3000" , nil )
39+
40+ server := & http.Server {
41+ Addr : ":3000" ,
42+ Handler : mux ,
43+ ReadTimeout : 10 * time .Second ,
44+ WriteTimeout : 10 * time .Second ,
45+ IdleTimeout : 120 * time .Second ,
46+ }
47+
48+ fmt .Println ("Server is starting on port 3000..." )
49+ if err := server .ListenAndServe (); err != nil && err != http.ErrServerClosed {
50+ fmt.Printf ("Error starting server: %s
51+ ", err )
52+ }
3953}
0 commit comments