-
Notifications
You must be signed in to change notification settings - Fork 2
/
lazy.go
88 lines (71 loc) · 1.71 KB
/
lazy.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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
package identity
import (
"crypto/tls"
"crypto/x509"
"github.com/michaelquigley/pfxlog"
"sync"
)
var _ Identity = &LazyIdentity{}
// LazyIdentity will delay calling identity.LoadIdentity(config) till it is first accessed.
type LazyIdentity struct {
Identity
*Config
loadOnce sync.Once
}
func (self *LazyIdentity) load() {
self.loadOnce.Do(func() {
var err error
self.Identity, err = LoadIdentity(*self.Config)
if err != nil {
pfxlog.Logger().Fatalf("error during lazy load of identity: %v", err)
}
})
}
func (self *LazyIdentity) Cert() *tls.Certificate {
self.load()
return self.Identity.Cert()
}
func (self *LazyIdentity) ServerCert() []*tls.Certificate {
self.load()
return self.Identity.ServerCert()
}
func (self *LazyIdentity) CA() *x509.CertPool {
self.load()
return self.Identity.CA()
}
func (self *LazyIdentity) CaPool() *CaPool {
self.load()
return self.Identity.CaPool()
}
func (self *LazyIdentity) ServerTLSConfig() *tls.Config {
self.load()
return self.Identity.ServerTLSConfig()
}
func (self *LazyIdentity) ClientTLSConfig() *tls.Config {
self.load()
return self.Identity.ClientTLSConfig()
}
func (self *LazyIdentity) Reload() error {
self.load()
return self.Identity.Reload()
}
func (self *LazyIdentity) WatchFiles() error {
self.load()
return self.Identity.WatchFiles()
}
func (self *LazyIdentity) StopWatchingFiles() {
self.load()
self.Identity.StopWatchingFiles()
}
func (self *LazyIdentity) SetCert(pem string) error {
self.load()
return self.Identity.SetCert(pem)
}
func (self *LazyIdentity) SetServerCert(pem string) error {
self.load()
return self.Identity.SetServerCert(pem)
}
func (self *LazyIdentity) GetConfig() *Config {
self.load()
return self.Identity.GetConfig()
}