-
Notifications
You must be signed in to change notification settings - Fork 92
/
options.go
54 lines (41 loc) · 1.43 KB
/
options.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
package gosip
import "github.com/ghettovoice/gosip/sip"
type RequestWithContextOption interface {
ApplyRequestWithContext(options *RequestWithContextOptions)
}
type RequestWithContextOptions struct {
ResponseHandler func(res sip.Response, request sip.Request)
Authorizer sip.Authorizer
ClientTransactionCallbacks
}
type ClientTransactionCallbacks struct {
OnAck, OnCancel func(sip.Request)
}
type withResponseHandler struct {
handler func(res sip.Response, request sip.Request)
}
func (o withResponseHandler) ApplyRequestWithContext(options *RequestWithContextOptions) {
options.ResponseHandler = o.handler
}
func WithResponseHandler(handler func(res sip.Response, request sip.Request)) RequestWithContextOption {
return withResponseHandler{handler}
}
type withAuthorizer struct {
authorizer sip.Authorizer
}
func (o withAuthorizer) ApplyRequestWithContext(options *RequestWithContextOptions) {
options.Authorizer = o.authorizer
}
func WithAuthorizer(authorizer sip.Authorizer) RequestWithContextOption {
return withAuthorizer{authorizer}
}
type withClientTxCallbacks struct {
onAckFn, onCancFn func(sip.Request)
}
func WithClientTransactionCallbacks(callbacks ClientTransactionCallbacks) RequestWithContextOption {
return withClientTxCallbacks{callbacks.OnAck, callbacks.OnCancel}
}
func (o withClientTxCallbacks) ApplyRequestWithContext(options *RequestWithContextOptions) {
options.OnAck = o.onAckFn
options.OnCancel = o.onCancFn
}