Replace ItemID with int

This commit is contained in:
ekzyis 2023-04-25 02:25:59 +02:00
parent 26aa14c9a1
commit 12143f1296
1 changed files with 4 additions and 6 deletions

10
hn.go
View File

@ -10,14 +10,12 @@ import (
"strconv" "strconv"
) )
type ItemID = int
type Story struct { type Story struct {
ID ItemID ID int
By string // username of author By string // username of author
Time int // UNIX timestamp Time int // UNIX timestamp
Descendants int // number of comments Descendants int // number of comments
Kids []ItemID Kids []int
Score int Score int
Title string Title string
Url string Url string
@ -66,7 +64,7 @@ func FetchHackerNewsTopStories() []Story {
return stories[:] return stories[:]
} }
func FetchStoryById(id ItemID) Story { func FetchStoryById(id int) Story {
url := fmt.Sprintf("https://hacker-news.firebaseio.com/v0/item/%d.json", id) url := fmt.Sprintf("https://hacker-news.firebaseio.com/v0/item/%d.json", id)
resp, err := http.Get(url) resp, err := http.Get(url)
if err != nil { if err != nil {
@ -84,7 +82,7 @@ func FetchStoryById(id ItemID) Story {
return story return story
} }
func ParseHackerNewsLink(link string) (ItemID, error) { func ParseHackerNewsLink(link string) (int, error) {
match := HackerNewsLinkRegexp.FindStringSubmatch(link) match := HackerNewsLinkRegexp.FindStringSubmatch(link)
if len(match) == 0 { if len(match) == 0 {
return -1, errors.New("input is not a hacker news link") return -1, errors.New("input is not a hacker news link")