go-indexnow
Introduction
This library is written in Go (Golang). It allows website owners to inform search engines about
the latest content changes on their website using the IndexNow API.
Please see IndexNow Documentation for details on the IndexNow API.
Installation
Install the library using the following command:
go get codeberg.org/threatint/go-indexnow
Usage
This library has only on function: IndexNow(). It accepts the following parameters:
host - the hostname your website
key - the API key
urls - a list of URLs ([]string] to submit to IndexNow. The URLs must match the host parameter.
Example
A simple example looks like this:
package main
import (
"fmt"
"os"
"codeberg.org/threatint/go-indexnow"
)
func main() {
urlList := []string{
"https://example.com/page1",
"https://example.com/page2",
}
result, err := indexnow.IndexNow("example.com", "<key>", urlList)
if err != nil {
fmt.Println(err)
os.exit(0xff)
}
switch result {
case indexnow.ResponseOk, indexnow.ResponseAccepted:
fmt.Printf("Successfully submitted %d URLs to IndexNow: %s", len(urlList), urlList)
case indexnow.ResponseBadRequest:
fmt.Println("bad request")
case indexnow.ResponseForbidden:
fmt.Println("forbidden - API key validation failed")
case indexnow.ResponseUnprocessableEntity:
fmt.Println("unprocessable entity - URLs do not belong to 'host' or 'key' not found")
case 429:
fmt.Println("rate limit exceeded - try again later")
default:
fmt.Printf("unexpected status code: %d", result)
}
}
FAQ
The IndexNow API limits the number of URLs per post to 10,000.
If you pass more than 10,000 URLs, the library will automatically split them into batches,
each containing a maximum of 10,000 URLs.
Some internet sources claim that only 10,000 URLs may be submitted via IndexNow API per day.
To our knowledge, this is not correct: the documentation states
You can submit up to 10,000 URLs per post (...)
Feedback
We would love to hear from you! Please contact us at help@threatin.eu
for feedback and general requests. Kindly raise an issue in Codeberg if you find a problem in the code.
Want to know what we do when we're not developing open-source software?
Find out at www.threatint.eu ;-)
License
Release under the MIT License. (see LICENSE)