updated initializers
This commit is contained in:
@@ -34,7 +34,7 @@ const (
|
||||
// 4. Obtain a new certificate
|
||||
// 5. Save To Disk
|
||||
// 6. Kickoff Renewal Routine
|
||||
func Init(cfg *Config) (*CertReloader, error) {
|
||||
func Init(cfg *Config, cleanup func()) (*CertReloader, error) {
|
||||
|
||||
// validate config
|
||||
err := CheckConfig(cfg)
|
||||
@@ -94,7 +94,7 @@ func Init(cfg *Config) (*CertReloader, error) {
|
||||
}
|
||||
|
||||
// return a cert reloader for the local cert
|
||||
return NewCertReloader(certFilePath, keyFilePath, logFile)
|
||||
return NewCertReloader(certFilePath, keyFilePath, logFile, cleanup)
|
||||
}
|
||||
|
||||
var (
|
||||
@@ -140,7 +140,7 @@ func Init(cfg *Config) (*CertReloader, error) {
|
||||
// kickoff renewal routine
|
||||
go renewalRoutine(cert)
|
||||
|
||||
return NewCertReloader(certFilePath, keyFilePath, logFile)
|
||||
return NewCertReloader(certFilePath, keyFilePath, logFile, cleanup)
|
||||
}
|
||||
|
||||
obtainNewCert:
|
||||
@@ -187,5 +187,5 @@ obtainNewCert:
|
||||
// kickoff renewal routine
|
||||
go renewalRoutine(cert)
|
||||
|
||||
return NewCertReloader(certFilePath, keyFilePath, logFile)
|
||||
return NewCertReloader(certFilePath, keyFilePath, logFile, cleanup)
|
||||
}
|
||||
|
||||
12
utils.go
12
utils.go
@@ -32,9 +32,9 @@ const localhost = "127.0.0.1"
|
||||
|
||||
// ListenAndServeTLSCustom allows to specify the simplecert and TLS configuration
|
||||
// and does not redirect the traffic arriving at port 80
|
||||
func ListenAndServeTLSCustom(addr string, handler http.Handler, cfg *Config, tlsconf *tls.Config, domains ...string) error {
|
||||
func ListenAndServeTLSCustom(addr string, handler http.Handler, cfg *Config, tlsconf *tls.Config, cleanup func(), domains ...string) error {
|
||||
|
||||
certReloader, err := Init(cfg)
|
||||
certReloader, err := Init(cfg, cleanup)
|
||||
if err != nil {
|
||||
log.Fatal("[FATAL] simplecert init failed: ", err)
|
||||
}
|
||||
@@ -56,13 +56,13 @@ func ListenAndServeTLSCustom(addr string, handler http.Handler, cfg *Config, tls
|
||||
}
|
||||
|
||||
// ListenAndServeTLSLocal is a util to use simplecert for local development
|
||||
func ListenAndServeTLSLocal(addr string, handler http.Handler, domains ...string) error {
|
||||
func ListenAndServeTLSLocal(addr string, handler http.Handler, cleanup func(), domains ...string) error {
|
||||
|
||||
cfg := Default
|
||||
cfg.Domains = domains
|
||||
cfg.CacheDir = "simplecert"
|
||||
cfg.Local = true
|
||||
certReloader, err := Init(cfg)
|
||||
certReloader, err := Init(cfg, cleanup)
|
||||
if err != nil {
|
||||
log.Fatal("[FATAL] simplecert init failed: ", err)
|
||||
}
|
||||
@@ -91,13 +91,13 @@ func ListenAndServeTLSLocal(addr string, handler http.Handler, domains ...string
|
||||
}
|
||||
|
||||
// ListenAndServeTLS is a util to use simplecert in production
|
||||
func ListenAndServeTLS(addr string, handler http.Handler, mail string, domains ...string) error {
|
||||
func ListenAndServeTLS(addr string, handler http.Handler, mail string, cleanup func(), domains ...string) error {
|
||||
|
||||
cfg := Default
|
||||
cfg.Domains = domains
|
||||
cfg.CacheDir = "simplecert"
|
||||
cfg.SSLEmail = mail
|
||||
certReloader, err := Init(cfg)
|
||||
certReloader, err := Init(cfg, cleanup)
|
||||
if err != nil {
|
||||
log.Fatal("[FATAL] simplecert init failed: ", err)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user