-
Notifications
You must be signed in to change notification settings - Fork 0
/
serve.go
32 lines (29 loc) · 854 Bytes
/
serve.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
package server
// ServerOption that configures a function Server.
type ServerOption func(server *Server)
// NewServer create a new Server instance that implements the Crossplane
// Function interface and is able to serve multiple subfunctions
// (aka server functions) at the same time.
//
// ServerFunctions are registered via the WithFunction option:
//
// server.NewServer(
// server.WithFunction(&MyFunction{})
// server.WithFunction(&MyOtherFunction{})
// // ...
// )
func NewServer(opts ...ServerOption) *Server {
server := &Server{
functions: map[string]ServerFunction{},
}
for _, o := range opts {
o(server)
}
return server
}
// WithFunction registers a ServerFunction at a Server with a given name.
func WithFunction(name string, fn ServerFunction) ServerOption {
return func(server *Server) {
server.functions[name] = fn
}
}