purge.go 676 B

1234567891011121314151617181920212223242526272829303132
  1. package dao
  2. import (
  3. "context"
  4. "net/url"
  5. "time"
  6. "go-common/library/log"
  7. )
  8. const _purgeURL = "http://cp.bilibili.co/api_purge.php"
  9. // PurgeCDN purges cdn.
  10. func (d *Dao) PurgeCDN(c context.Context, file string) (err error) {
  11. defer func() {
  12. if err == nil {
  13. return
  14. }
  15. time.Sleep(time.Second)
  16. if e := d.PushCDN(c, file); e != nil {
  17. log.Error("d.PushCDN(%s) error(%+v)", file, e)
  18. }
  19. }()
  20. params := url.Values{}
  21. params.Set("sid", "2d0586d2c63fb82a69b20c8992811055")
  22. params.Set("file", file)
  23. if err = d.httpClient.Get(c, _purgeURL, "", params, nil); err != nil {
  24. log.Error("d.httpClient.Get() error(%+v)", err)
  25. PromError("purge:刷新CDN")
  26. }
  27. return
  28. }