forked from Abovo-Media/go-ews
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathoptions.go
65 lines (54 loc) · 1.17 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
55
56
57
58
59
60
61
62
63
64
65
package ews
import (
"crypto/tls"
"net/http"
"time"
"github.com/Azure/go-ntlmssp"
)
type Option func(c *client) error
func WithLogger(l Logger) Option {
return func(c *client) error {
if l == nil {
c.log = NopLogger()
} else {
c.log = l
}
return nil
}
}
func WithDefaultLogger() Option { return WithLogger(DefaultLogger()) }
func WithBasicAuth(user, pass string) Option {
return func(c *client) error {
c.auth = [2]string{user, pass}
return nil
}
}
// WithTimeout sets the Timeout field on the http.Client.
func WithTimeout(t time.Duration) Option {
return func(c *client) error {
c.http.Timeout = t
return nil
}
}
func WithTransport(t http.RoundTripper) Option {
return func(c *client) error {
c.http.Transport = t
return nil
}
}
func WithDefaultTransport(skipTls bool) Option {
t := http.DefaultTransport
if skipTls {
t.(*http.Transport).TLSClientConfig = &tls.Config{InsecureSkipVerify: true}
}
return WithTransport(t)
}
func WithNTLM(skipTls bool) Option {
return WithTransport(new(ntlmssp.Negotiator))
}
func WithExchangeImpersonation(v string) Option {
return func(c *client) error {
c.header.ImpersonateSmtpAddress(v)
return nil
}
}