func StartPeriodicStateBackup(m *letsencrypt.Manager) { for range m.Watch() { // First run will call a cache save that overwrites with null data if LE_FIRSTRUN { log.Info("[SSL] State change detected, storing") StoreLEState(m) } LE_FIRSTRUN = true } }
// Cache caches letsencrypt data for the given Manager in the Google Cloud // Storage object identified by the getURL and putURL values. // See the package comment for details on obtaining these values. func Cache(m *letsencrypt.Manager, getURL, putURL string) error { var data []byte r, err := http.Get(getURL) if err != nil { return fmt.Errorf("letscloud: reading cache: %v", err) } data, err = ioutil.ReadAll(r.Body) r.Body.Close() if err != nil { return fmt.Errorf("letscloud: reading cache: %v", err) } if r.StatusCode == http.StatusOK && len(data) > 0 { if err := m.Unmarshal(string(data)); err != nil { return fmt.Errorf("letscloud: reading cache: %v", err) } } go func() { for range m.Watch() { req, err := http.NewRequest("PUT", putURL, strings.NewReader(m.Marshal())) if err != nil { log.Printf("letscloud: writing cache: %v", err) continue } r, err := http.DefaultClient.Do(req) if err != nil { log.Printf("letscloud: writing cache: %v", err) continue } if r.StatusCode != http.StatusOK { log.Printf("letscloud: writing cache: %v", r.Status) } } }() return nil }