ping.go 698 B

123456789101112131415161718192021222324252627282930313233
  1. package sitemap
  2. import (
  3. "context"
  4. "fmt"
  5. "net/http"
  6. )
  7. type ToUrlInterface interface {
  8. ToUrl(context.Context) string
  9. }
  10. func PingBing(site ToUrlInterface, ctx context.Context) (err error) {
  11. _, err = http.Get(fmt.Sprintf("http://www.bing.com/webmaster/ping.aspx?siteMap=%s", site.ToUrl(ctx)))
  12. return
  13. }
  14. func PingGoogle(site ToUrlInterface, ctx context.Context) (err error) {
  15. _, err = http.Get(fmt.Sprintf("https://www.google.com/webmasters/sitemaps/ping?sitemap=%s", site.ToUrl(ctx)))
  16. return
  17. }
  18. func PingAll(site ToUrlInterface, ctx context.Context) (err error) {
  19. if err = PingGoogle(site, ctx); err != nil {
  20. return
  21. }
  22. if err = PingBing(site, ctx); err != nil {
  23. return
  24. }
  25. return
  26. }