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
package gatewayhttp
import (
"errors"
"net/http"
)
type ServerOptions struct {
Cluster *ClusterAPI
OAuth *OAuth
Downloads *Downloads
}
type Server struct {
handler http.Handler
}
func NewServer(opts ServerOptions) (*Server, error) {
if opts.Cluster == nil && opts.OAuth == nil && opts.Downloads == nil {
return nil, errors.New("gatewayhttp: server has no routes")
}
mux := http.NewServeMux()
if opts.Cluster != nil {
opts.Cluster.Register(mux)
}
if opts.OAuth != nil {
opts.OAuth.Register(mux)
}
if opts.Downloads != nil {
opts.Downloads.Register(mux)
}
return &Server{handler: mux}, nil
}
func (s *Server) Handler() http.Handler { return s.handler }