forked from davidfowl/signalr-ports
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserveroptions.go
61 lines (54 loc) · 1.86 KB
/
serveroptions.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
package signalr
import (
"reflect"
"time"
)
// UseHub sets the hub instance used by the server
func UseHub(hub HubInterface) func(*Server) error {
return func(s *Server) error {
s.newHub = func() HubInterface { return hub }
return nil
}
}
// HubFactory sets the function which returns the hub instance for every hub method invocation
// The function might create a new hub instance on every invocation.
// If hub instances should be created and initialized by a DI framework,
// the frameworks factory method can be called here.
func HubFactory(factoryFunc func() HubInterface) func(*Server) error {
return func(s *Server) error {
s.newHub = factoryFunc
return nil
}
}
// SimpleHubFactory sets a HubFactory which creates a new hub with the underlying type
// of hubProto on each hub method invocation.
func SimpleHubFactory(hubProto HubInterface) func(*Server) error {
return HubFactory(
func() HubInterface {
return reflect.New(reflect.ValueOf(hubProto).Elem().Type()).Interface().(HubInterface)
})
}
// HubChanReceiveTimeout is the timeout for receiving stream items from the client.
// If the hub method is not able to receive a stream item during the timeout duration,
// the server will send a completion with error
func HubChanReceiveTimeout(duration time.Duration) func(*Server) error {
return func(s *Server) error {
s.hubChanReceiveTimeout = duration
return nil
}
}
// StructuredLogger is the simplest logging interface for structured logging.
// See github.com/go-kit/kit/log
type StructuredLogger interface {
Log(keyvals ...interface{}) error
}
// Logger stets the logger used by the server to log info events.
// If debug is true, debug log event are generated, too
func Logger(logger StructuredLogger, debug bool) func(*Server) error {
return func(s *Server) error {
i, d := buildInfoDebugLogger(logger, debug)
s.info = i
s.dbg = d
return nil
}
}