gitlin/pages/explore.go

45 行
1.4 KiB
Go
Raw 通常表示 履歴

package pages
import (
2023-06-06 20:25:00 +09:00
"github.com/gofiber/fiber/v2"
2023-06-06 20:25:00 +09:00
"gitler.moe/suwako/gitlin/utils"
)
type Items struct {
2023-06-06 20:25:00 +09:00
Fullname string
Description string
HtmlUrl string
Stars int64
Forks int64
Watchers int64
Language string
License string
}
func HandleExplore(c *fiber.Ctx) error {
2023-06-06 20:25:00 +09:00
// get trending repos
trendingRepos := utils.GetRequest("https://api.github.com/search/repositories?q=code&sort=stars&order=desc&per_page=25")
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
var trendingReposArray []Items
for _, item := range gjsonArray {
trendingReposArray = append(trendingReposArray, Items{
Fullname: item.Get("full_name").String(),
Description: item.Get("description").String(),
HtmlUrl: item.Get("html_url").String(),
Stars: item.Get("stargazers_count").Int(),
Forks: item.Get("forks_count").Int(),
Watchers: item.Get("watchers_count").Int(),
Language: item.Get("language").String(),
License: item.Get("license").Get("name").String(),
})
}
2023-06-06 20:25:00 +09:00
return c.Render("explore", fiber.Map{
2023-06-07 11:03:32 +09:00
"title": "エクスプローラー",
"ver": utils.Ver,
"ves": utils.Ves,
2023-06-06 20:25:00 +09:00
"repos": trendingReposArray,
})
}