2019-11-09 16:35:54 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"net/http"
|
|
|
|
)
|
|
|
|
|
2019-12-22 18:29:30 +00:00
|
|
|
type Cdn interface {
|
|
|
|
// Purge url from CDN
|
|
|
|
Purge(url string)
|
|
|
|
}
|
|
|
|
|
|
|
|
// BunnyCDN
|
|
|
|
type BunnyCdn struct {
|
|
|
|
// Access Key
|
|
|
|
key string
|
|
|
|
}
|
|
|
|
|
2019-12-24 11:29:14 +00:00
|
|
|
var bunnyCdnUrl = "https://bunnycdn.com"
|
|
|
|
|
2019-12-22 19:27:12 +00:00
|
|
|
func (cdn *BunnyCdn) Purge(url string) {
|
2019-11-09 16:35:54 +00:00
|
|
|
client := &http.Client{}
|
2019-12-24 11:29:14 +00:00
|
|
|
req, _ := http.NewRequest("POST", bunnyCdnUrl+"/api/purge?url="+url, nil)
|
2019-11-09 16:35:54 +00:00
|
|
|
req.Header.Add("Content-Type", "application/json")
|
|
|
|
req.Header.Add("Accept", "application/json")
|
2019-12-22 18:29:30 +00:00
|
|
|
req.Header.Add("AccessKey", cdn.key)
|
2019-11-09 16:35:54 +00:00
|
|
|
_, _ = client.Do(req)
|
|
|
|
}
|