https://github.com/robtec/newsapi
Golang client + library for https://newsapi.org/
https://github.com/robtec/newsapi
command-line golang library newsapi
Last synced: 4 months ago
JSON representation
Golang client + library for https://newsapi.org/
- Host: GitHub
- URL: https://github.com/robtec/newsapi
- Owner: robtec
- Created: 2018-05-12T20:35:18.000Z (about 8 years ago)
- Default Branch: master
- Last Pushed: 2018-09-22T14:22:59.000Z (over 7 years ago)
- Last Synced: 2025-08-14T22:27:08.662Z (10 months ago)
- Topics: command-line, golang, library, newsapi
- Language: Go
- Size: 18.6 KB
- Stars: 14
- Watchers: 3
- Forks: 5
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# NewsAPI Go
[](https://goreportcard.com/report/github.com/robtec/newsapi-go) [](https://godoc.org/github.com/robtec/newsapi/api) [](https://travis-ci.org/robtec/newsapi)
Golang client and library for https://newsapi.org
## Install
```bash
$ go get github.com/robtec/newsapi
$ go install ./cmd/news
```
## CLI Usage
You must register with News API to get an API Key
https://newsapi.org/register
```bash
$ export NEWS_API_KEY=
# Get the Top Headlines from Ireland, with 'Eurovision' as the Query
$ news top -c ie "Eurovision"
+--------------------------------+--------------------------------+----------------+-------------+
| TITLE | DESCRIPTION | SOURCE | POSTED |
+--------------------------------+--------------------------------+----------------+-------------+
| How Ryan's Eurovision chutzpah | Didn't the heart nearly burst | Independent.ie | 2 hours ago |
| outfoxed us all | out of my chest when the | | |
| | Portuguese gals chimed in | | |
| | unison | | |
+--------------------------------+--------------------------------+----------------+-------------+
...
```
See `news help` for more options
## Library Usage
```golang
package main
import (
"fmt"
"net/http"
"github.com/robtec/newsapi/api"
)
func main() {
httpClient := http.Client{}
key := "my-api-key"
url := "https://newsapi.org"
query := "Elon Musk"
// Create a client, passing in the above
client, err := api.New(httpClient, key, url)
// Create options for Ireland and Business
opts := api.Options{Country: "ie", Category: "business"}
// Get Top Headlines with options from above
topHeadlines, err := client.TopHeadlines(opts)
// Different options
moreOpts := api.Options{Language: "en", Q: query, SortBy: "popularity"}
// Get Everything with options from above
everything, err := client.Everything(moreOpts)
}
```
## Contribution
Checkout source
```bash
$ mkdir -p $GOPATH/src/github.com/ && cd $_
$ git clone https://github.com/robtec/newsapi.git
$ cd newsapi
$ make deps // install dependencies
```
Checkout the `Makefile` for extra development options