func (cw *CertFileWatcher) Start() error {
	cw.latch.Starting()

	certLastMod, keyLastMod, err := cw.keyPairLastModified()
	if err != nil {
		cw.latch.Stopped()
		return err
	}

	ticker := time.NewTicker(cw.PollIntervalOrDefault())
	defer ticker.Stop()

	cw.latch.Started()
	var certMod, keyMod time.Time
	for {
		select {
		case <-ticker.C:
			certMod, keyMod, err = cw.keyPairLastModified()
			if err != nil {
				return err
			}
			// wait for both to update
			if keyMod.After(keyLastMod) && certMod.After(certLastMod) {
				if err = cw.Reload(); err != nil {
					return err
				}
				keyLastMod = keyMod
				certLastMod = certMod
			}
		case <-cw.latch.NotifyStopping():
			cw.latch.Stopped()
			return nil
		}
	}
}
// Start watches the cert and triggers a reload on change
Start watches the cert and triggers a reload on change
// Start watches the cert and triggers a reload on change
func (cw *CertFileWatcher) Start() error {
	cw.latch.Starting()
	certLastMod, keyLastMod, err := cw.keyPairLastModified()
	if err != nil {
		cw.latch.Stopped()
		return err
	}
	ticker := time.NewTicker(cw.PollIntervalOrDefault())
	defer ticker.Stop()
	cw.latch.Started()
	var certMod, keyMod time.Time
	for {
		select {
		case <-ticker.C:
			certMod, keyMod, err = cw.keyPairLastModified()
			if err != nil {
				return err
			}
			if keyMod.After(keyLastMod) && certMod.After(certLastMod) {
				if err = cw.Reload(); err != nil {
					return err
				}
				keyLastMod = keyMod
				certLastMod = certMod
			}
		case <-cw.latch.NotifyStopping():
			cw.latch.Stopped()
			return nil
		}
	}
}
func ( cw * CertFileWatcher ) Start ( ) error { cw . latch . Starting ( ) certLastMod , keyLastMod , err := cw . keyPairLastModified ( ) if err != nil { cw . latch . Stopped ( ) return err } ticker := time . NewTicker ( cw . PollIntervalOrDefault ( ) ) defer ticker . Stop ( ) cw . latch . Started ( ) var certMod , keyMod time . Time for { select { case <- ticker . C : certMod , keyMod , err = cw . keyPairLastModified ( ) if err != nil { return err } if keyMod . After ( keyLastMod ) && certMod . After ( certLastMod ) { if err = cw . Reload ( ) ; err != nil { return err } keyLastMod = keyMod certLastMod = certMod } case <- cw . latch . NotifyStopping ( ) : cw . latch . Stopped ( ) return nil } } }
Start watches the cert and triggers a reload on change
Start watches the cert and triggers a reload on change
// wait for both to update