Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
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