newsapi

package
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 15, 2026 License: Apache-2.0 Imports: 9 Imported by: 0

README

NewsAPI Client

This package provides a client for the NewsAPI API, which is used to interact with the NewsAPI service.

References:

Documentation

Overview

newsapi implements an API client for NewsAPI (https://newsapi.org/docs)

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewTools added in v0.1.0

func NewTools(apikey string, opts ...client.ClientOpt) ([]tool.Tool, error)

Types

type Article

type Article struct {
	Source      Source    `json:"source"`
	Title       string    `json:"title"`
	Author      string    `json:"author,omitempty"`
	Description string    `json:"description,omitempty"`
	Url         string    `json:"url,omitempty"`
	ImageUrl    string    `json:"urlToImage,omitempty"`
	PublishedAt time.Time `json:"publishedAt,omitempty"`
	Content     string    `json:"content,omitempty"`
}

type ArticlesRequest added in v0.1.0

type ArticlesRequest struct {
	Query          string `json:"q,omitempty" jsonschema:"Search keywords or phrases"`
	SearchIn       string `` /* 143-byte string literal not displayed */
	Sources        string `` /* 140-byte string literal not displayed */
	Domains        string `` /* 130-byte string literal not displayed */
	ExcludeDomains string `json:"excludeDomains,omitempty" jsonschema:"A comma-separated string of domains to remove from the results"`
	From           string `` /* 148-byte string literal not displayed */
	To             string `json:"to,omitempty" jsonschema:"A date and optional time for the newest article allowed. ISO 8601 format"`
	Language       string `json:"language,omitempty" jsonschema:"The 2-letter ISO-639-1 code of the language you want to get articles for"`
	SortBy         string `json:"sortBy,omitempty" jsonschema:"The order to sort the articles in. Possible options: relevancy, popularity, publishedAt"`
	PageSize       int    `json:"pageSize,omitempty" jsonschema:"The number of results to return per page (max 100)"`
	Page           int    `json:"page,omitempty" jsonschema:"Use this to page through the results"`
}

func (*ArticlesRequest) Values added in v0.1.0

func (r *ArticlesRequest) Values() url.Values

type Client

type Client struct {
	*client.Client
}

func New

func New(ApiKey string, opts ...client.ClientOpt) (*Client, error)

func (*Client) Articles

func (c *Client) Articles(ctx context.Context, req *ArticlesRequest) ([]Article, error)

Returns articles

func (*Client) Headlines

func (c *Client) Headlines(ctx context.Context, req *HeadlinesRequest) ([]Article, error)

Returns headlines

func (*Client) Sources

func (c *Client) Sources(ctx context.Context, req *SourcesRequest) ([]Source, error)

Sources returns all news sources based on the provided request parameters

type HeadlinesRequest added in v0.1.0

type HeadlinesRequest struct {
	Query    string `json:"q,omitempty" jsonschema:"Keywords or phrases to search for in the article title and body"`
	Category string `` /* 170-byte string literal not displayed */
	Country  string `json:"country,omitempty" jsonschema:"The 2-letter ISO 3166-1 code of the country you want to get headlines for"`
	Sources  string `` /* 184-byte string literal not displayed */
	Language string `json:"language,omitempty" jsonschema:"The 2-letter ISO-639-1 code of the language you want to get headlines for"`
	PageSize int    `json:"pageSize,omitempty" jsonschema:"The number of results to return per page (max 100)"`
	Page     int    `json:"page,omitempty" jsonschema:"Use this to page through the results"`
}

func (*HeadlinesRequest) Values added in v0.1.0

func (r *HeadlinesRequest) Values() url.Values

type Source

type Source struct {
	Id          string `json:"id"`
	Name        string `json:"name"`
	Description string `json:"description,omitempty"`
	Url         string `json:"url,omitempty"`
	Category    string `json:"category,omitempty"`
	Language    string `json:"language,omitempty"`
	Country     string `json:"country,omitempty"`
}

type SourcesRequest added in v0.1.0

type SourcesRequest struct {
	Category string `` /* 168-byte string literal not displayed */
	Language string `json:"language,omitempty" jsonschema:"The 2-letter ISO-639-1 code of the language you want to get sources for"`
	Country  string `json:"country,omitempty" jsonschema:"The 2-letter ISO 3166-1 code of the country you want to get sources for"`
}

func (*SourcesRequest) Values added in v0.1.0

func (r *SourcesRequest) Values() url.Values

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL