news

package
v0.0.0-...-bf5f488 Latest Latest
Warning

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

Go to latest
Published: May 14, 2023 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Article

type Article struct {
	Title string `json:"title"`
	URL   string `json:"url"`
}

type News

type News struct {
	Articles []Article `json:"articles"`
}

The `NewsClient` struct is used to define an API key, tokens, and base URL, as well as an http client to make requests to the news API. The `NewClient` function is used to initialize the `NewsClient` struct with an API key and any necessary tokens.

The `Query` method takes an endpoint and a map of parameters as input and makes a GET request to the news API using the `BaseURL`, `APIKey`, and `Tokens` fields of the `NewsClient` struct. It then encodes the query parameters into the URL and returns the response body as a byte slice.

The `GetHotNews()` and `GetLatestNewsInCategory(category string)` functions use the `Query` method to make requests to the news API, passing the appropriate endpoint and parameters, and then unmarshal the JSON response into the `News` struct.

type NewsClient

type NewsClient struct {
	APIKey  string
	Tokens  map[string]string
	BaseURL string
	Client  *http.Client
}

func NewClient

func NewClient(apiKey string) *NewsClient

func (*NewsClient) GetHotNews

func (nc *NewsClient) GetHotNews() (News, error)

GetHotNews returns a list of hot news articles

func (*NewsClient) GetLatestNewsInCategory

func (nc *NewsClient) GetLatestNewsInCategory(category string) (News, error)

GetLatestNewsInCategory returns a list of latest news articles in a specific category

func (*NewsClient) Query

func (nc *NewsClient) Query(endpoint string, params map[string]string) ([]byte, error)

Jump to

Keyboard shortcuts

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