Newsapi
Go client for newsapi (https://newsapi.org/)
Install / Use
/learn @barthr/NewsapiREADME
NewsAPI Go Client
Go client for communicating with the newsapi's api.
Getting Started
These instructions will get you a copy of the project up and running on your local machine for development and testing purposes.
Prerequisites
go get github.com/barthr/newsapi
Next, register for free at (https://newsapi.org/register), get yourself a free api key and keep it somewhere safe.
Examples
Retrieving all sources
package main
import (
"fmt"
"net/http"
"context"
"github.com/barthr/newsapi"
)
func main() {
c := newsapi.NewClient("<API KEY>", newsapi.WithHTTPClient(http.DefaultClient))
sources, err := c.GetSources(context.Background(), nil)
if err != nil {
panic(err)
}
for _, s := range sources.Sources {
fmt.Println(s.Description)
}
}
Retrieving all sources for a specific country (Great Britain in this case)
package main
import (
"fmt"
"net/http"
"context"
"github.com/barthr/newsapi"
)
func main() {
c := newsapi.NewClient("<API KEY>", newsapi.WithHTTPClient(http.DefaultClient))
sources, err := c.GetSources(context.Background(), &newsapi.SourceParameters{
Country: "gb",
})
if err != nil {
panic(err)
}
for _, s := range sources.Sources {
fmt.Println(s.Name)
}
}
Retrieving top headlines
package main
import (
"fmt"
"net/http"
"context"
"github.com/barthr/newsapi"
)
func main() {
c := newsapi.NewClient("<API KEY>", newsapi.WithHTTPClient(http.DefaultClient))
articles, err := c.GetTopHeadlines(context.Background(), &newsapi.TopHeadlineParameters{
Sources: []string{ "cnn", "time" },
})
if err != nil {
panic(err)
}
for _, s := range articles.Articles {
fmt.Printf("%+v\n\n", s)
}
}
Retrieving all articles
package main
import (
"fmt"
"net/http"
"context"
"github.com/barthr/newsapi"
)
func main() {
c := newsapi.NewClient("<API KEY>", newsapi.WithHTTPClient(http.DefaultClient))
articles, err := c.GetEverything(context.Background(), &newsapi.EverythingParameters{
Sources: []string{ "cnn", "time" },
})
if err != nil {
panic(err)
}
for _, s := range articles.Articles {
fmt.Printf("%+v\n\n", s)
}
}
License
This project is licensed under the MIT License
Acknowledgments
- Inspired by github golang client
Related Skills
node-connect
347.0kDiagnose OpenClaw node connection and pairing failures for Android, iOS, and macOS companion apps
xurl
347.0kA CLI tool for making authenticated requests to the X (Twitter) API. Use this skill when you need to post tweets, reply, quote, search, read posts, manage followers, send DMs, upload media, or interact with any X API v2 endpoint.
frontend-design
107.8kCreate distinctive, production-grade frontend interfaces with high design quality. Use this skill when the user asks to build web components, pages, or applications. Generates creative, polished code that avoids generic AI aesthetics.
openai-whisper-api
347.0kTranscribe audio via OpenAI Audio Transcriptions API (Whisper).
