-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.go
executable file
·57 lines (50 loc) · 1.33 KB
/
server.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 server
import (
"fmt"
"net/http"
"time"
"github.com/thavlik/t4vd/base/pkg/base"
compiler "github.com/thavlik/t4vd/compiler/pkg/api"
"go.uber.org/zap"
"github.com/pacedotdev/oto/otohttp"
"github.com/thavlik/t4vd/slideshow/pkg/api"
"github.com/thavlik/t4vd/slideshow/pkg/imgcache"
"github.com/thavlik/t4vd/slideshow/pkg/markercache"
)
type Server struct {
bucket string
imgCache imgcache.ImgCache
markerCache markercache.MarkerCache
compiler compiler.Compiler
log *zap.Logger
}
func NewServer(
bucket string,
imgCache imgcache.ImgCache,
markerCache markercache.MarkerCache,
compiler compiler.Compiler,
log *zap.Logger,
) *Server {
return &Server{
bucket: bucket,
imgCache: imgCache,
markerCache: markerCache,
log: log,
}
}
func (s *Server) ListenAndServe(port int) error {
otoServer := otohttp.NewServer()
api.RegisterSlideShow(otoServer, s)
mux := http.NewServeMux()
mux.Handle("/", otoServer)
mux.HandleFunc("/healthz", base.HealthHandler)
mux.HandleFunc("/readyz", base.ReadyHandler)
mux.HandleFunc("/frame", s.handleGetFrame())
s.log.Info("listening forever", zap.Int("port", port))
return (&http.Server{
Handler: mux,
Addr: fmt.Sprintf("0.0.0.0:%d", port),
WriteTimeout: 15 * time.Second,
ReadTimeout: 15 * time.Second,
}).ListenAndServe()
}