MCPcopy Index your code
hub / github.com/caddyserver/certmagic / newWithCache

Function newWithCache

config.go:239–295  ·  view source on GitHub ↗

newWithCache ensures that cfg is a valid config by populating zero-value fields from the Default Config. If certCache is nil, this function panics.

(certCache *Cache, cfg Config)

Source from the content-addressed store, hash-verified

237// zero-value fields from the Default Config. If certCache is
238// nil, this function panics.
239func newWithCache(certCache *Cache, cfg Config) *Config {
240 if certCache == nil {
241 panic("cannot make a valid config without a pointer to a certificate cache")
242 }
243
244 if cfg.OnDemand == nil {
245 cfg.OnDemand = Default.OnDemand
246 }
247 if !cfg.MustStaple {
248 cfg.MustStaple = Default.MustStaple
249 }
250 if cfg.Issuers == nil {
251 cfg.Issuers = Default.Issuers
252 if cfg.Issuers == nil {
253 // at least one issuer is absolutely required if not nil
254 cfg.Issuers = []Issuer{NewACMEIssuer(&cfg, DefaultACME)}
255 }
256 }
257 if cfg.RenewalWindowRatio == 0 {
258 cfg.RenewalWindowRatio = Default.RenewalWindowRatio
259 }
260 if cfg.OnEvent == nil {
261 cfg.OnEvent = Default.OnEvent
262 }
263 if cfg.KeySource == nil {
264 cfg.KeySource = Default.KeySource
265 }
266 if cfg.DefaultServerName == "" {
267 cfg.DefaultServerName = Default.DefaultServerName
268 }
269 if cfg.FallbackServerName == "" {
270 cfg.FallbackServerName = Default.FallbackServerName
271 }
272 if cfg.Storage == nil {
273 cfg.Storage = Default.Storage
274 }
275 if cfg.Logger == nil {
276 cfg.Logger = Default.Logger
277 }
278
279 // absolutely don't allow a nil storage,
280 // because that would make almost anything
281 // a config can do pointless
282 if cfg.Storage == nil {
283 cfg.Storage = defaultFileStorage
284 }
285
286 // absolutely don't allow a nil logger either,
287 // because that would result in panics
288 if cfg.Logger == nil {
289 cfg.Logger = defaultLogger
290 }
291
292 cfg.certCache = certCache
293
294 return &cfg
295}
296

Callers 2

NewDefaultFunction · 0.85
NewFunction · 0.85

Calls 1

NewACMEIssuerFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…