-
Notifications
You must be signed in to change notification settings - Fork 4
/
wrapper.go
57 lines (47 loc) · 1.04 KB
/
wrapper.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
package continuous
import (
"context"
"net"
"net/http"
"time"
"google.golang.org/grpc"
)
type httpServer struct {
*http.Server
}
func (s *httpServer) Stop() error {
return s.Server.Close()
}
func (s *httpServer) GracefulStop() error {
ctx, cancel := context.WithTimeout(context.Background(), time.Second)
defer cancel()
return s.Server.Shutdown(ctx)
}
func WrapHTTPServer(s *http.Server) Continuous {
return &httpServer{s}
}
type httpServerTLS struct {
*httpServer
certFile string
keyFile string
}
func WrapHTTPServerTLS(s *http.Server, certFile, keyFile string) Continuous {
return &httpServerTLS{httpServer: &httpServer{s}, certFile: certFile, keyFile: keyFile}
}
func (s *httpServerTLS) Serve(lis net.Listener) error {
return s.ServeTLS(lis, s.certFile, s.keyFile)
}
type grpcServer struct {
*grpc.Server
}
func (s *grpcServer) Stop() error {
s.Server.Stop()
return nil
}
func (s *grpcServer) GracefulStop() error {
s.Server.GracefulStop()
return nil
}
func WrapGRPCServer(s *grpc.Server) Continuous {
return &grpcServer{s}
}