-
Notifications
You must be signed in to change notification settings - Fork 4
/
server.go
57 lines (50 loc) · 1.45 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 (
"github.com/GaruGaru/ciak/pkg/config"
"github.com/GaruGaru/ciak/pkg/media/details"
"github.com/GaruGaru/ciak/pkg/media/discovery"
"github.com/GaruGaru/ciak/pkg/server/auth"
"github.com/gorilla/mux"
log "github.com/sirupsen/logrus"
"net/http"
)
const (
serverVersion = "0.0.2"
)
type CiakServer struct {
Config config.CiakServerConfig
MediaDiscovery discovery.MediaDiscovery
Authenticator auth.Authenticator
DetailsRetriever *details.Controller
}
func NewCiakServer(
conf config.CiakServerConfig,
discovery discovery.MediaDiscovery,
authenticator auth.Authenticator,
DetailsRetriever *details.Controller,
) CiakServer {
return CiakServer{
Config: conf,
MediaDiscovery: discovery,
Authenticator: authenticator,
DetailsRetriever: DetailsRetriever,
}
}
func (s CiakServer) Run() error {
log.WithFields(log.Fields{
"bind": s.Config.ServerBinding,
"version": serverVersion,
}).Info("Ciak server started")
router := mux.NewRouter()
s.initRouting(router)
return http.ListenAndServe(s.Config.ServerBinding, router)
}
func (s CiakServer) initRouting(router *mux.Router) {
router.HandleFunc("/probe", ProbeHandler)
router.HandleFunc("/", s.MediaListHandler)
router.HandleFunc("/media/{media}", s.MediaStreamingHandler)
router.HandleFunc("/login", s.LoginPageHandler)
router.HandleFunc("/api/login", s.LoginApiHandler)
router.Use(LoggingMiddleware)
router.Use(s.SessionAuthMiddleware)
}