blob: 1d56f86e2587ccf59a047e278e1a7a45f11cb165 (
plain)
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
|
package worker
import (
"context"
"net/http"
)
type ServerTask struct {
server *http.Server
}
func NewServerTask(server *http.Server) *ServerTask {
return &ServerTask{
server: server,
}
}
func (self *ServerTask) Start(ctx context.Context) error {
go func() {
// nolint: errcheck
self.server.ListenAndServe()
}()
<-ctx.Done()
return self.server.Shutdown(ctx)
}
|