-
Notifications
You must be signed in to change notification settings - Fork 1
/
runhttp.go
64 lines (55 loc) · 1.26 KB
/
runhttp.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
58
59
60
61
62
63
64
package httpserver
import (
"fmt"
"net/http"
"aduu.dev/utils/runmanager"
)
// Runnable impplements a runnable http service.
type Runnable struct {
Endpoint string
Handler http.Handler
}
// Run runs the http server on the specified port to return html.
func (s *Runnable) Run(m *runmanager.RunManager) {
server := http.Server{
Addr: s.Endpoint,
Handler: s.Handler,
}
m.Run(&runmanager.Runner{
Run: func() error {
fmt.Println("Running http server on", server.Addr)
if err := server.ListenAndServe(); err != nil && err != http.ErrServerClosed {
return err
}
return nil
},
Shutdown: func() error {
fmt.Println("Shutting down http server")
return server.Shutdown(m.Context)
},
})
}
/*
// Run the http server on the specified port to return html.
func (s *SingleFolderAPI) Run(m *RunManager) {
server := http.Server{
Addr: s.HTTPServerAddress(),
Handler: &httpServerImpl{
settings: s,
},
}
m.Run(&Runner{
Run: func() error {
fmt.Println("Running http server on", server.Addr)
if err := server.ListenAndServe(); err != nil && err != http.ErrServerClosed {
return err
}
return nil
},
Shutdown: func() error {
fmt.Println("Shutting down http server")
return server.Shutdown(m.Context)
},
})
}
*/