forked from ghettovoice/gosip
-
Notifications
You must be signed in to change notification settings - Fork 0
/
options.go
36 lines (27 loc) · 960 Bytes
/
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
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
}
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}
}