{"id":20279190,"url":"https://github.com/peterhellberg/hn","last_synced_at":"2025-07-18T22:08:39.700Z","repository":{"id":21596346,"uuid":"24916477","full_name":"peterhellberg/hn","owner":"peterhellberg","description":"Go library for the Hacker News API","archived":false,"fork":false,"pushed_at":"2020-04-07T07:04:04.000Z","size":19,"stargazers_count":19,"open_issues_count":0,"forks_count":7,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-11T06:32:22.630Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"https://github.com/HackerNews/API","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/peterhellberg.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2014-10-07T23:41:16.000Z","updated_at":"2024-06-17T23:18:12.000Z","dependencies_parsed_at":"2022-08-21T05:40:10.907Z","dependency_job_id":null,"html_url":"https://github.com/peterhellberg/hn","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/peterhellberg/hn","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/peterhellberg%2Fhn","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/peterhellberg%2Fhn/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/peterhellberg%2Fhn/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/peterhellberg%2Fhn/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/peterhellberg","download_url":"https://codeload.github.com/peterhellberg/hn/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/peterhellberg%2Fhn/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":265845093,"owners_count":23837729,"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":[],"created_at":"2024-11-14T13:28:47.430Z","updated_at":"2025-07-18T22:08:39.678Z","avatar_url":"https://github.com/peterhellberg.png","language":"Go","readme":"# hn\n\nGo library for the [Hacker News API](https://github.com/HackerNews/API)\n\n[![GoDoc](https://godoc.org/github.com/peterhellberg/hn?status.svg)](https://godoc.org/github.com/peterhellberg/hn)\n[![Build Status](https://travis-ci.org/peterhellberg/hn.svg?branch=master)](https://travis-ci.org/peterhellberg/hn)\n[![License MIT](https://img.shields.io/badge/license-MIT-lightgrey.svg?style=flat)](https://github.com/peterhellberg/hn#license-mit)\n\n## Installation\n\n```bash\ngo get -u github.com/peterhellberg/hn\n```\n\n## Services\n\nThe client currently delegates to implementations of three interfaces:\n[ItemsService](https://godoc.org/github.com/peterhellberg/hn#ItemsService),\n[LiveService](https://godoc.org/github.com/peterhellberg/hn#LiveService) and\n[UsersService](https://godoc.org/github.com/peterhellberg/hn#UsersService).\n\n## Example usage\n\nShowing the current top ten stories\n\n```go\npackage main\n\nimport (\n  \"fmt\"\n\n  \"github.com/peterhellberg/hn\"\n)\n\nfunc main() {\n  hn := hn.DefaultClient\n\n  ids, err := hn.TopStories()\n  if err != nil {\n    panic(err)\n  }\n\n  for i, id := range ids[:10] {\n    item, err := hn.Item(id)\n    if err != nil {\n      panic(err)\n    }\n\n    fmt.Println(i, \"–\", item.Title, \"\\n   \", item.URL, \"\\n\")\n  }\n}\n```\n\nShowing the current top ten stories using goroutines, a channel and a wait group\n\n```go\npackage main\n\nimport (\n  \"fmt\"\n  \"net/http\"\n  \"sync\"\n  \"time\"\n\n  \"github.com/peterhellberg/hn\"\n)\n\ntype indexItem struct {\n  Index int\n  Item  *hn.Item\n}\n\nvar (\n  items    = map[int]*hn.Item{}\n  messages = make(chan indexItem)\n)\n\nfunc main() {\n  hn := hn.NewClient(\u0026http.Client{\n    Timeout: time.Duration(5 * time.Second),\n  })\n\n  ids, err := hn.TopStories()\n  if err != nil {\n    panic(err)\n  }\n\n  go func() {\n    for i := range messages {\n      items[i.Index] = i.Item\n    }\n  }()\n\n  var wg sync.WaitGroup\n\n  for i, id := range ids[:10] {\n    wg.Add(1)\n    go func(i, id int) {\n      defer wg.Done()\n\n      item, err := hn.Item(id)\n      if err != nil {\n        panic(err)\n      }\n\n      messages \u003c- indexItem{i, item}\n    }(i, id)\n  }\n\n  wg.Wait()\n\n  for i := 0; i \u003c 10; i++ {\n    fmt.Println(i, \"–\", items[i].Title, \"\\n   \", items[i].URL, \"\\n\")\n  }\n}\n```\n\nShowing information about a given user (first argument)\n\n```go\npackage main\n\nimport (\n  \"fmt\"\n  \"os\"\n\n  \"github.com/peterhellberg/hn\"\n)\n\nfunc main() {\n  if len(os.Args) \u003c 2 {\n    return\n  }\n\n  if u, err := hn.DefaultClient.User(os.Args[1]); err == nil {\n    fmt.Println(\"ID:   \", u.ID)\n    fmt.Println(\"About:\", u.About)\n    fmt.Println(\"Karma:\", u.Karma)\n  }\n}\n```\n\n## License (MIT)\n\nCopyright (c) 2014-2015 [Peter Hellberg](http://c7.se/)\n\n\u003e Permission is hereby granted, free of charge, to any person obtaining\n\u003e a copy of this software and associated documentation files (the\n\u003e \"Software\"), to deal in the Software without restriction, including\n\u003e without limitation the rights to use, copy, modify, merge, publish,\n\u003e distribute, sublicense, and/or sell copies of the Software, and to\n\u003e permit persons to whom the Software is furnished to do so, subject to\n\u003e the following conditions:\n\n\u003e The above copyright notice and this permission notice shall be\n\u003e included in all copies or substantial portions of the Software.\n\n\u003e THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND,\n\u003e EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF\n\u003e MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND\n\u003e NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE\n\u003e LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION\n\u003e OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION\n\u003e WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpeterhellberg%2Fhn","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpeterhellberg%2Fhn","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpeterhellberg%2Fhn/lists"}