本文整理匯總了Golang中rsc/io/letsencrypt.Manager.Unmarshal方法的典型用法代碼示例。如果您正苦於以下問題:Golang Manager.Unmarshal方法的具體用法?Golang Manager.Unmarshal怎麽用?Golang Manager.Unmarshal使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類rsc/io/letsencrypt.Manager
的用法示例。
在下文中一共展示了Manager.Unmarshal方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: 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
}
示例2: GetLEState
func GetLEState(m *letsencrypt.Manager) {
checkKey := "cache"
thisStore := &RedisClusterStorageManager{KeyPrefix: LEKeyPrefix, HashKeys: false}
connected := thisStore.Connect()
log.Debug("[SSL] --> Connected to DB")
if !connected {
log.Error("[SSL] --> SSL Backup recovery failed: redis connection failed")
return
}
cryptoText, rErr := thisStore.GetKey(checkKey)
if rErr != nil {
log.Warning("[SSL] --> No SSL backup: ", rErr)
return
}
secret := rightPad2Len(config.Secret, "=", 32)
sslState := decrypt([]byte(secret), cryptoText)
m.Unmarshal(sslState)
}