hn

package
v0.0.0-...-4d6a655 Latest Latest
Warning

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

Go to latest
Published: Nov 1, 2021 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func New

func New(opts ...ClientOption) *client

New creates a client

Types

type Client

type Client interface {
	FetchTopStories() ([]int, error)
	FetchItem(id int) (*Item, error)
}

Client is a interface to expose methods to interact with the hacker news api

type ClientOption

type ClientOption func(c *client)

ClientOption is an interface for a functional option

func WithBaseUrl

func WithBaseUrl(baseUrl string) ClientOption

WithBaseUrl is a functional option to configure the client's base URL

type Item

type Item struct {
	ID        int       `json:"id"`
	Type      string    `json:"type"`
	Text      string    `json:"text"`
	URL       string    `json:"url"`
	Score     int       `json:"score"`
	Title     string    `json:"title"`
	CreatedAt time.Time `json:"createdAt"`
	CreatedBy string    `json:"createdBy"`
	Dead      bool      `json:"dead"`
	Deleted   bool      `json:"deleted"`
}

Item represents the API response structure of an item

type Mock

type Mock struct {
	mock.Mock
}

func (*Mock) FetchItem

func (m *Mock) FetchItem(id int) (*Item, error)

func (*Mock) FetchTopStories

func (m *Mock) FetchTopStories() ([]int, error)

Jump to

Keyboard shortcuts

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