github.com/philippseith/signalr@v0.6.3/party.go (about) 1 package signalr 2 3 import ( 4 "context" 5 "time" 6 7 "github.com/go-kit/log" 8 ) 9 10 // Party is the common base of Server and Client. The Party methods are only used internally, 11 // but the interface is public to allow using Options on Party as parameters for external functions 12 type Party interface { 13 context() context.Context 14 cancel() 15 16 onConnected(hc hubConnection) 17 onDisconnected(hc hubConnection) 18 19 invocationTarget(hc hubConnection) interface{} 20 21 timeout() time.Duration 22 setTimeout(timeout time.Duration) 23 24 setHandshakeTimeout(timeout time.Duration) 25 26 keepAliveInterval() time.Duration 27 setKeepAliveInterval(interval time.Duration) 28 29 insecureSkipVerify() bool 30 setInsecureSkipVerify(skip bool) 31 32 originPatterns() [] string 33 setOriginPatterns(orgs []string) 34 35 chanReceiveTimeout() time.Duration 36 setChanReceiveTimeout(interval time.Duration) 37 38 streamBufferCapacity() uint 39 setStreamBufferCapacity(capacity uint) 40 41 allowReconnect() bool 42 43 enableDetailedErrors() bool 44 setEnableDetailedErrors(enable bool) 45 46 loggers() (info StructuredLogger, dbg StructuredLogger) 47 setLoggers(info StructuredLogger, dbg StructuredLogger) 48 49 prefixLoggers(connectionID string) (info StructuredLogger, dbg StructuredLogger) 50 51 maximumReceiveMessageSize() uint 52 setMaximumReceiveMessageSize(size uint) 53 } 54 55 func newPartyBase(parentContext context.Context, info log.Logger, dbg log.Logger) partyBase { 56 ctx, cancelFunc := context.WithCancel(parentContext) 57 return partyBase{ 58 ctx: ctx, 59 cancelFunc: cancelFunc, 60 _timeout: time.Second * 30, 61 _handshakeTimeout: time.Second * 15, 62 _keepAliveInterval: time.Second * 5, 63 _chanReceiveTimeout: time.Second * 5, 64 _streamBufferCapacity: 10, 65 _maximumReceiveMessageSize: 1 << 15, // 32KB 66 _enableDetailedErrors: false, 67 _insecureSkipVerify: false, 68 _originPatterns: nil, 69 info: info, 70 dbg: dbg, 71 } 72 } 73 74 type partyBase struct { 75 ctx context.Context 76 cancelFunc context.CancelFunc 77 _timeout time.Duration 78 _handshakeTimeout time.Duration 79 _keepAliveInterval time.Duration 80 _chanReceiveTimeout time.Duration 81 _streamBufferCapacity uint 82 _maximumReceiveMessageSize uint 83 _enableDetailedErrors bool 84 _insecureSkipVerify bool 85 _originPatterns []string 86 info StructuredLogger 87 dbg StructuredLogger 88 } 89 90 func (p *partyBase) context() context.Context { 91 return p.ctx 92 } 93 94 func (p *partyBase) cancel() { 95 p.cancelFunc() 96 } 97 98 func (p *partyBase) timeout() time.Duration { 99 return p._timeout 100 } 101 102 func (p *partyBase) setTimeout(timeout time.Duration) { 103 p._timeout = timeout 104 } 105 106 func (p *partyBase) HandshakeTimeout() time.Duration { 107 return p._handshakeTimeout 108 } 109 110 func (p *partyBase) setHandshakeTimeout(timeout time.Duration) { 111 p._handshakeTimeout = timeout 112 } 113 114 func (p *partyBase) keepAliveInterval() time.Duration { 115 return p._keepAliveInterval 116 } 117 118 func (p *partyBase) setKeepAliveInterval(interval time.Duration) { 119 p._keepAliveInterval = interval 120 } 121 122 func (p *partyBase) insecureSkipVerify() bool { 123 return p._insecureSkipVerify 124 } 125 func (p *partyBase) setInsecureSkipVerify(skip bool) { 126 p._insecureSkipVerify = skip 127 } 128 129 func (p *partyBase) originPatterns() []string { 130 return p._originPatterns 131 } 132 func (p *partyBase) setOriginPatterns(origins []string) { 133 p._originPatterns = origins 134 } 135 136 func (p *partyBase) chanReceiveTimeout() time.Duration { 137 return p._chanReceiveTimeout 138 } 139 140 func (p *partyBase) setChanReceiveTimeout(interval time.Duration) { 141 p._chanReceiveTimeout = interval 142 } 143 144 func (p *partyBase) streamBufferCapacity() uint { 145 return p._streamBufferCapacity 146 } 147 148 func (p *partyBase) setStreamBufferCapacity(capacity uint) { 149 p._streamBufferCapacity = capacity 150 } 151 152 func (p *partyBase) maximumReceiveMessageSize() uint { 153 return p._maximumReceiveMessageSize 154 } 155 156 func (p *partyBase) setMaximumReceiveMessageSize(size uint) { 157 p._maximumReceiveMessageSize = size 158 } 159 160 func (p *partyBase) enableDetailedErrors() bool { 161 return p._enableDetailedErrors 162 } 163 164 func (p *partyBase) setEnableDetailedErrors(enable bool) { 165 p._enableDetailedErrors = enable 166 } 167 168 func (p *partyBase) setLoggers(info StructuredLogger, dbg StructuredLogger) { 169 p.info = info 170 p.dbg = dbg 171 } 172 173 func (p *partyBase) loggers() (info StructuredLogger, debug StructuredLogger) { 174 return p.info, p.dbg 175 }