Fix certmagic usage

This commit is contained in:
世界 2023-07-20 20:03:20 +08:00
parent e0058ca9c5
commit 407cf68e59
No known key found for this signature in database
GPG key ID: CD109927C34A63C4

View file

@ -21,6 +21,7 @@ import (
type acmeWrapper struct { type acmeWrapper struct {
ctx context.Context ctx context.Context
cfg *certmagic.Config cfg *certmagic.Config
cache *certmagic.Cache
domain []string domain []string
} }
@ -29,7 +30,7 @@ func (w *acmeWrapper) Start() error {
} }
func (w *acmeWrapper) Close() error { func (w *acmeWrapper) Close() error {
w.cfg.Unmanage(w.domain) w.cache.Stop()
return nil return nil
} }
@ -77,10 +78,11 @@ func startACME(ctx context.Context, options option.InboundACMEOptions) (*tls.Con
acmeConfig.ExternalAccount = (*acme.EAB)(options.ExternalAccount) acmeConfig.ExternalAccount = (*acme.EAB)(options.ExternalAccount)
} }
config.Issuers = []certmagic.Issuer{certmagic.NewACMEIssuer(config, acmeConfig)} config.Issuers = []certmagic.Issuer{certmagic.NewACMEIssuer(config, acmeConfig)}
config = certmagic.New(certmagic.NewCache(certmagic.CacheOptions{ cache := certmagic.NewCache(certmagic.CacheOptions{
GetConfigForCert: func(certificate certmagic.Certificate) (*certmagic.Config, error) { GetConfigForCert: func(certificate certmagic.Certificate) (*certmagic.Config, error) {
return config, nil return config, nil
}, },
}), *config) })
return config.TLSConfig(), &acmeWrapper{ctx, config, options.Domain}, nil config = certmagic.New(cache, *config)
return config.TLSConfig(), &acmeWrapper{ctx: ctx, cfg: config, cache: cache, domain: options.Domain}, nil
} }