Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/jellydator/newsapi-go
Go client for NewsAPI
https://github.com/jellydator/newsapi-go
Last synced: 9 days ago
JSON representation
Go client for NewsAPI
- Host: GitHub
- URL: https://github.com/jellydator/newsapi-go
- Owner: jellydator
- Created: 2022-02-22T20:56:15.000Z (over 2 years ago)
- Default Branch: master
- Last Pushed: 2024-03-02T09:40:26.000Z (8 months ago)
- Last Synced: 2024-07-31T20:53:21.567Z (3 months ago)
- Language: Go
- Homepage:
- Size: 32.2 KB
- Stars: 7
- Watchers: 1
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-go - newsapi-go - Go client for [NewsAPI](https://newsapi.org/). (Third-party APIs / Utility/Miscellaneous)
- awesome-go-extra - newsapi-go - 02-22T20:56:15Z|2022-06-30T06:40:10Z| (Third-party APIs / Fail injection)
README
# newsapi
[![GoDoc](https://godoc.org/github.com/jellydator/newsapi-go?status.png)](https://godoc.org/github.com/jellydator/newsapi-go)
[![Coverage Status](https://coveralls.io/repos/github/jellydator/newsapi-go/badge.svg?branch=master)](https://coveralls.io/github/jellydator/newsapi-go?branch=master)
[![Go Report Card](https://goreportcard.com/badge/github.com/jellydator/newsapi-go)](https://goreportcard.com/report/github.com/jellydator/newsapi-go)Go client implementation for the NewsAPI.
## Installation
```
go get github.com/jellydator/newsapi-go
```## Usage
Simply, we create a client using `NewClient` function, by default only an API
key is required, however some other parameters can be set using variadic
option functions.
```go
client := newsapi.NewClient("apiKey", newsapi.WithHTTPClient(&http.Client{
Timeout: 5 * time.Second,
}))
```## Endpoints
### Everything
`Everything` retrieves all articles based on provided parameters.
Full endpoint documentation can be viewed [here](https://newsapi.org/docs/endpoints/everything).
```go
articles, pageCount, err := client.Everything(context.Background(), newsapi.EverythingParams{
Query: "cryptocurrency",
})
if err != nil {
// handle error
}
// success
```### Top Headlines
`TopHeadlines` retrieves top headlines articles based on provided parameters.
Full endpoint documentation can be viewed [here](https://newsapi.org/docs/endpoints/top-headlines).
```go
articles, pageCount, err := client.TopHeadlines(context.Background(), newsapi.TopHeadlinesParams{
Query: "cryptocurrency",
})
if err != nil {
// handle error
}
// success
```### Sources
`Sources` retrieves available sources based on provided parameters.
Full endpoint documentation can be viewed [here](https://newsapi.org/docs/endpoints/sources).
```go
sources, err := client.Sources(context.Background(), newsapi.SourceParams{
Categories: []newsapi.Category{
newsapi.CategoryBusiness,
newsapi.CategoryScience,
},
})
if err != nil {
// handle error
}
// success
```