Purge BunnyCDN 10 seconds after published
parent
6b41fcfb09
commit
7795fa171d
|
@ -0,0 +1,18 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
)
|
||||
|
||||
func Purge(url string) {
|
||||
accessKey, err := GetBunnyCDNKey()
|
||||
if err != nil || len(accessKey) == 0 {
|
||||
return
|
||||
}
|
||||
client := &http.Client{}
|
||||
req, _ := http.NewRequest("POST", "https://bunnycdn.com/api/purge?url="+url, nil)
|
||||
req.Header.Add("Content-Type", "application/json")
|
||||
req.Header.Add("Accept", "application/json")
|
||||
req.Header.Add("AccessKey", accessKey)
|
||||
_, _ = client.Do(req)
|
||||
}
|
|
@ -28,3 +28,12 @@ func GetBlogURL() (string, error) {
|
|||
}
|
||||
return blogURL, nil
|
||||
}
|
||||
|
||||
|
||||
func GetBunnyCDNKey() (string, error) {
|
||||
bunnyCDNKey := os.Getenv("BUNNY_CDN_KEY")
|
||||
if len(bunnyCDNKey) == 0 || bunnyCDNKey == "" {
|
||||
return "", errors.New("BUNNY_CDN_KEY not specified")
|
||||
}
|
||||
return bunnyCDNKey, nil
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue