本文整理匯總了Golang中rsc/io/letsencrypt.Manager.Watch方法的典型用法代碼示例。如果您正苦於以下問題:Golang Manager.Watch方法的具體用法?Golang Manager.Watch怎麽用?Golang Manager.Watch使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類rsc/io/letsencrypt.Manager
的用法示例。
在下文中一共展示了Manager.Watch方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: StartPeriodicStateBackup
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
}
}
示例2: Cache
// 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
}