Skip to content

Commit 4667bb9

Browse files
committed
expose shutdown
1 parent c9a8a2d commit 4667bb9

1 file changed

Lines changed: 14 additions & 7 deletions

File tree

‎sdk/handler.go‎

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package sdk
22

33
import (
4+
"context"
45
"crypto/tls"
56
"fmt"
67
"net"
@@ -13,7 +14,8 @@ const activatePath = "/Plugin.Activate"
1314
// Handler is the base to create plugin handlers.
1415
// It initializes connections and sockets to listen to.
1516
type Handler struct {
16-
mux *http.ServeMux
17+
mux *http.ServeMux
18+
server *http.Server
1719
}
1820

1921
// NewHandler creates a new Handler with an http mux.
@@ -25,16 +27,21 @@ func NewHandler(manifest string) Handler {
2527
fmt.Fprintln(w, manifest)
2628
})
2729

28-
return Handler{mux: mux}
30+
server := &http.Server{
31+
Handler: mux,
32+
}
33+
34+
return Handler{mux: mux, server: server}
2935
}
3036

3137
// Serve sets up the handler to serve requests on the passed in listener
3238
func (h Handler) Serve(l net.Listener) error {
33-
server := http.Server{
34-
Addr: l.Addr().String(),
35-
Handler: h.mux,
36-
}
37-
return server.Serve(l)
39+
h.server.Addr = l.Addr().String()
40+
return h.server.Serve(l)
41+
}
42+
43+
func (h Handler) Shutdown(ctx context.Context) error {
44+
return h.server.Shutdown(ctx)
3845
}
3946

4047
// ServeTCP makes the handler to listen for request in a given TCP address.

0 commit comments

Comments
 (0)