https://github.com/johnpatek/newsapi-go
Golang client for News API
https://github.com/johnpatek/newsapi-go
news newsapi rest rest-api
Last synced: 11 months ago
JSON representation
Golang client for News API
- Host: GitHub
- URL: https://github.com/johnpatek/newsapi-go
- Owner: johnpatek
- License: mit
- Created: 2024-02-22T04:51:01.000Z (over 2 years ago)
- Default Branch: master
- Last Pushed: 2024-02-24T16:00:26.000Z (over 2 years ago)
- Last Synced: 2024-06-21T14:30:16.033Z (about 2 years ago)
- Topics: news, newsapi, rest, rest-api
- Language: Go
- Homepage:
- Size: 34.2 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# NewsAPI Go Client
[](http://pkg.go.dev/github.com/johnpatek/newsapi-go)
[](https://codecov.io/gh/johnpatek/newsapi-go)
[](https://goreportcard.com/report/github.com/johnpatek/newsapi-go)
Go client package for [NewsAPI](https://newsapi.org).
## Usage
The following [example](_example/main.go) demonstrates basic usage.
```go
package main
import (
"fmt"
"os"
"github.com/johnpatek/newsapi-go"
"github.com/kr/pretty"
)
func main() {
if len(os.Args) > 1 {
// get the top headlines about Lionel Messi from US based outlets
messiHeadlines, err := newsapi.GetTopHeadlines(os.Args[1], newsapi.TopHeadlinesParameters{
Q: "messi",
Category: newsapi.Sports,
Country: newsapi.USA,
})
if err != nil {
fmt.Println(err)
return
}
// print the top articles as a formatted JSON
for _, headline := range messiHeadlines.Articles {
pretty.Println(headline)
}
} else {
fmt.Printf("Usage: example ")
}
}
```
This example can be built and run using the following commands:
```bash
make build
./bin/example
```