explore.go 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. package pages
  2. import (
  3. "github.com/gofiber/fiber/v2"
  4. "gitler.moe/suwako/gitlin/utils"
  5. )
  6. type Items struct {
  7. Fullname string
  8. Description string
  9. HtmlUrl string
  10. Stars int64
  11. Forks int64
  12. Watchers int64
  13. Language string
  14. License string
  15. }
  16. func HandleExplore(c *fiber.Ctx) error {
  17. // get trending repos
  18. trendingRepos := utils.GetRequest("https://api.github.com/search/repositories?q=code&sort=stars&order=desc&per_page=25")
  19. gjsonArray := trendingRepos.Get("items").Array() // gjson.Result when I ask for an array. idiots, anyway so I have to do jank shit like this and I hate it. at least it works and is fast enough
  20. var trendingReposArray []Items
  21. for _, item := range gjsonArray {
  22. trendingReposArray = append(trendingReposArray, Items{
  23. Fullname: item.Get("full_name").String(),
  24. Description: item.Get("description").String(),
  25. HtmlUrl: item.Get("html_url").String(),
  26. Stars: item.Get("stargazers_count").Int(),
  27. Forks: item.Get("forks_count").Int(),
  28. Watchers: item.Get("watchers_count").Int(),
  29. Language: item.Get("language").String(),
  30. License: item.Get("license").Get("name").String(),
  31. })
  32. }
  33. return c.Render("explore", fiber.Map{
  34. "title": "エクスプローラー",
  35. "ver": utils.Ver,
  36. "ves": utils.Ves,
  37. "repos": trendingReposArray,
  38. })
  39. }