/
apiserver_http.go
64 lines (49 loc) · 1.34 KB
/
apiserver_http.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
// Copyright 2019 NetApp, Inc. All Rights Reserved.
package rest
import (
"context"
"fmt"
"net/http"
log "github.com/sirupsen/logrus"
"github.com/netapp/trident/config"
"github.com/netapp/trident/core"
)
var orchestrator core.Orchestrator
type APIServerHTTP struct {
server *http.Server
}
func NewHTTPServer(p core.Orchestrator, address, port string) *APIServerHTTP {
orchestrator = p
apiServer := &APIServerHTTP{
server: &http.Server{
Addr: fmt.Sprintf("%s:%s", address, port),
Handler: NewRouter(),
ReadTimeout: config.HTTPTimeout,
WriteTimeout: config.HTTPTimeout,
},
}
log.WithField("address", apiServer.server.Addr).Info("Initializing HTTP REST frontend.")
return apiServer
}
func (s *APIServerHTTP) Activate() error {
go func() {
log.WithField("address", s.server.Addr).Info("Activating HTTP REST frontend.")
err := s.server.ListenAndServe()
if err != nil {
log.Fatal(err)
}
}()
return nil
}
func (s *APIServerHTTP) Deactivate() error {
log.WithField("address", s.server.Addr).Info("Deactivating HTTP REST frontend.")
ctx, cancel := context.WithTimeout(context.Background(), config.HTTPTimeout)
defer cancel()
return s.server.Shutdown(ctx)
}
func (s *APIServerHTTP) GetName() string {
return "HTTP REST"
}
func (s *APIServerHTTP) Version() string {
return config.OrchestratorAPIVersion
}