{"id":16175770,"url":"https://github.com/alexferrari88/gohn","last_synced_at":"2025-03-19T01:30:26.805Z","repository":{"id":60755325,"uuid":"543917481","full_name":"alexferrari88/GoHN","owner":"alexferrari88","description":"Hacker News API wrapper for Go","archived":false,"fork":false,"pushed_at":"2023-07-18T08:48:50.000Z","size":630,"stargazers_count":30,"open_issues_count":0,"forks_count":2,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-11T09:08:08.228Z","etag":null,"topics":["api","go","golang","golang-library","hacker-news","hacktoberfest","hacktoberfest2022"],"latest_commit_sha":null,"homepage":"https://pkg.go.dev/github.com/alexferrari88/gohn/pkg/gohn","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/alexferrari88.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-10-01T06:29:08.000Z","updated_at":"2025-02-24T12:05:16.000Z","dependencies_parsed_at":"2024-06-19T01:55:12.194Z","dependency_job_id":"62fd8769-e59a-45d8-a93a-88b2ba917137","html_url":"https://github.com/alexferrari88/GoHN","commit_stats":{"total_commits":69,"total_committers":3,"mean_commits":23.0,"dds":0.1159420289855072,"last_synced_commit":"2de2d63305280800b58e9eec204dee9465fd5620"},"previous_names":[],"tags_count":12,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alexferrari88%2FGoHN","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alexferrari88%2FGoHN/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alexferrari88%2FGoHN/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alexferrari88%2FGoHN/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/alexferrari88","download_url":"https://codeload.github.com/alexferrari88/GoHN/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243955697,"owners_count":20374374,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["api","go","golang","golang-library","hacker-news","hacktoberfest","hacktoberfest2022"],"created_at":"2024-10-10T04:46:13.574Z","updated_at":"2025-03-19T01:30:26.481Z","avatar_url":"https://github.com/alexferrari88.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"﻿# GoHN — Hacker News API Wrapper for Go\n\n\u003cdiv align=\"center\"\u003e\n\u003ca href=\"https://pkg.go.dev/github.com/alexferrari88/gohn/pkg/gohn\"\u003e\u003cimg src=\"https://pkg.go.dev/badge/github.com/alexferrari88/gohn.svg\" alt=\"Go Reference\"\u003e\u003c/a\u003e\n\u003c/div\u003e\n\u003cdiv align=\"center\"\u003e\n\u003cimg src=\"img/logo_1.svg\" width=\"300\" style=\"margin: 0 auto;\" /\u003e\n\u003c/div\u003e\n\nGoHN is a wrapper for the [Hacker News API](https://github.com/HackerNews/API) for Go, inspired by the excellent [go-github](https://github.com/google/go-github) library.\n\nIt facilitates the use of the API by providing a simple interface to the API endpoints.\n\n## Features 🚀\n\n- Get the top/new/best/ask/show/job stories\n- Retrieve all comments (with metadata) for a story using goroutines to speed up the process\n- Retrieve the comments ordered as they appear in the story on the website\n- Apply filters to retrieved items (stories, comments)\n- Can be used with a custom http.Client instance (to use a proxy, for example)\n\n## Usage 💻\n\nRefer to the [GoDoc](https://pkg.go.dev/github.com/alexferrari88/gohn/pkg/gohn) for the full API reference.\n\n### Example\n\nRefer to [example/main.go](example/main.go) for a full example on how to retrieve the top stories' IDs and the all the comments for the first one.\n\n```go\n    // Instantiate a new client to retrieve data from the Hacker News API\n    hn, _ := gohn.NewClient(nil)\n\n    // Use background context\n    ctx := context.Background()\n\n    // Get the top 500 stories' IDs\n    topStoriesIds, _ := hn.Stories.GetTopIDs(ctx)\n\n    var story *gohn.Item\n    // Retrieve the details of the first one\n    if len(topStoriesIds) \u003e 0 \u0026\u0026 topStoriesIds[0] != nil {\n        story, _ = hn.Items.Get(ctx, *topStoriesIds[0])\n    }\n\n    if story == nil {\n        panic(\"No story found\")\n    }\n\n    // Print the story's title\n    fmt.Println(\"Title:\", *story.Title)\n\n    // Print the story's author\n    fmt.Println(\"Author:\", *story.By)\n\n    // Print the story's score\n    fmt.Println(\"Score:\", *story.Score)\n\n    // Print the story's URL\n    fmt.Println(\"URL:\", *story.URL)\n\n    fmt.Println()\n    fmt.Println()\n\n    if story.Kids == nil {\n        fmt.Println(\"No comments found\")\n        return\n    }\n\n    // Retrieve all the comments for that story\n    // UnescapeHTML is applied to each retrieved item to unescape HTML characters\n\n    commentsMap, err := hn.Items.FetchAllKids(ctx, story, processors.UnescapeHTML())\n\n    if err != nil {\n        panic(err)\n    }\n    if len(commentsMap) == 0 {\n        fmt.Println(\"No comments found\")\n        return\n    }\n\n    fmt.Printf(\"Comments found: %d\\n\", len(commentsMap))\n    fmt.Println()\n\n    // Create a Story struct to hold the story and its comments\n    storyWithComments := gohn.Story{\n        Parent:          story,\n        CommentsByIdMap: commentsMap,\n    }\n\n    // Calculate the position of each comment in the story\n    storyWithComments.SetCommentsPosition()\n\n    // Get an ordered list of comments' IDs (ordered by position)\n    orderedIDs, err := storyWithComments.GetOrderedCommentsIDs()\n\n    if err != nil {\n        panic(err)\n    }\n\n    // Print the comments\n    for _, id := range orderedIDs {\n        comment := commentsMap[id]\n        if comment.Text != nil {\n            fmt.Println(*comment.Text)\n            fmt.Println()\n        }\n    }\n```\n\n## Semantic Versioning 🥚\n\nAs this library is not yet in version 1.0.0, the API may have breaking changes between minor versions.\n\n## Contributing 🤝🏼\n\nFeel free to fork this repo and create a PR. I will review them and merge, if ok.\n\n## License 📝\n\n[MIT](https://choosealicense.com/licenses/mit/)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falexferrari88%2Fgohn","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Falexferrari88%2Fgohn","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falexferrari88%2Fgohn/lists"}