@@ -35,18 +35,27 @@ type Webhook interface {
3535}
3636
3737type server struct {
38- hook Webhook
39- path string
38+ hook Webhook
39+ path string
40+ includePathCheck bool
4041}
4142
4243// ProcessPayloadFunc is a common function for payload return values
4344type ProcessPayloadFunc func (payload interface {}, header Header )
4445
46+ // Handler returns the webhook http.Handler for use in your own Mux implementation
47+ func Handler (hook Webhook ) http.Handler {
48+ return & server {
49+ hook : hook ,
50+ }
51+ }
52+
4553// Run runs a server
4654func Run (hook Webhook , addr string , path string ) error {
4755 srv := & server {
48- hook : hook ,
49- path : path ,
56+ hook : hook ,
57+ path : path ,
58+ includePathCheck : true ,
5059 }
5160
5261 s := & http.Server {Addr : addr , Handler : srv }
@@ -58,8 +67,9 @@ func Run(hook Webhook, addr string, path string) error {
5867func RunServer (s * http.Server , hook Webhook , path string ) error {
5968
6069 srv := & server {
61- hook : hook ,
62- path : path ,
70+ hook : hook ,
71+ path : path ,
72+ includePathCheck : true ,
6373 }
6474
6575 s .Handler = srv
@@ -74,8 +84,9 @@ func RunServer(s *http.Server, hook Webhook, path string) error {
7484func RunTLSServer (s * http.Server , hook Webhook , path string ) error {
7585
7686 srv := & server {
77- hook : hook ,
78- path : path ,
87+ hook : hook ,
88+ path : path ,
89+ includePathCheck : true ,
7990 }
8091
8192 s .Handler = srv
@@ -91,9 +102,12 @@ func (s *server) ServeHTTP(w http.ResponseWriter, r *http.Request) {
91102 http .Error (w , "405 Method not allowed" , http .StatusMethodNotAllowed )
92103 return
93104 }
94- if r .URL .Path != s .path {
95- http .Error (w , "404 Not found" , http .StatusNotFound )
96- return
105+
106+ if s .includePathCheck {
107+ if r .URL .Path != s .path {
108+ http .Error (w , "404 Not found" , http .StatusNotFound )
109+ return
110+ }
97111 }
98112
99113 s .hook .ParsePayload (w , r )
0 commit comments