本文整理汇总了Golang中rsc/io/letsencrypt.Manager.Marshal方法的典型用法代码示例。如果您正苦于以下问题:Golang Manager.Marshal方法的具体用法?Golang Manager.Marshal怎么用?Golang Manager.Marshal使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类rsc/io/letsencrypt.Manager
的用法示例。
在下文中一共展示了Manager.Marshal方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: StoreLEState
func StoreLEState(m *letsencrypt.Manager) {
log.Debug("Storing SSL backup")
log.Debug("[SSL] --> Connecting to DB")
thisStore := &RedisClusterStorageManager{KeyPrefix: LEKeyPrefix, HashKeys: false}
connected := thisStore.Connect()
log.Debug("--> Connected to DB")
if !connected {
log.Error("[SSL] --> SSL Backup save failed: redis connection failed")
return
}
state := m.Marshal()
secret := rightPad2Len(config.Secret, "=", 32)
cryptoText := encrypt([]byte(secret), state)
rErr := thisStore.SetKey("cache", cryptoText, -1)
if rErr != nil {
log.Error("[SSL] --> Failed to store SSL backup: ", rErr)
return
}
}
示例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
}