Go SDK provides access to the News API v3 from Go applications.
Installation
go get github.com/Newscatcher/newscatcher-go
Basic usage
import (
"context"
newscatcher "github.com/Newscatcher/newscatcher-go"
newscatcherclient "github.com/Newscatcher/newscatcher-go/client"
"github.com/Newscatcher/newscatcher-go/option"
)
client := newscatcherclient.NewClient(
option.WithApiKey("YOUR_API_KEY"),
)
response, err := client.Search.Post(
context.TODO(),
&newscatcher.SearchPostRequest{
Q: "renewable energy",
PredefinedSources: []string{"top 50 US"},
Lang: []string{"en"},
From: "2024-01-01",
To: "2024-06-30",
},
)
Error handling
import (
"github.com/Newscatcher/newscatcher-go/core"
"fmt"
)
response, err := client.Search.Post(...)
if err != nil {
if apiErr, ok := err.(*core.APIError); ok {
fmt.Println(apiErr.Error())
fmt.Println(apiErr.StatusCode)
}
return err
}
For complete documentation, including specific error types, retry configuration,
and timeouts, see the
GitHub repository.
If you use our legacy Go SDK (Konfig-based), see our Legacy
SDKs documentation. We recommend
migrating to this newer SDK for improved features and ongoing support.
Resources