update: Add JSON query support

This commit is contained in:
ngn
2024-03-21 21:52:14 +03:00
parent 67b6f22fb0
commit 787727b425
4 changed files with 36 additions and 10 deletions

View File

@ -8,6 +8,7 @@ import (
"net/url"
"os"
"strconv"
"strings"
"github.com/bigkevmcd/go-configparser"
"github.com/gofiber/fiber/v2"
@ -27,13 +28,17 @@ type Repo struct {
var Packages []Package
type Package struct {
Name string
Repo string
Desc string
Size string
Deps string
URL string
Ver string
Name string `json:"name"`
Repo string `json:"repo"`
Desc string `json:"desc"`
Size string `json:"size"`
Deps []string `json:"depends"`
URL string `json:"url"`
Ver string `json:"version"`
}
func (p Package) StrDeps() string {
return ListToStr(p.Deps)
}
func LoadPackgae(repo *configparser.ConfigParser, s string) (Package, error) {
@ -64,11 +69,17 @@ func LoadPackgae(repo *configparser.ConfigParser, s string) (Package, error) {
}
pkg.Size = SizeFromBytes(size)
pkg.Deps, err = repo.Get(s, "depends")
deps, err := repo.Get(s, "depends")
if err != nil {
return pkg, err
}
if deps == "" {
pkg.Deps = []string{}
}else {
pkg.Deps = strings.Split(deps, "\n")
}
return pkg, nil
}

View File

@ -13,6 +13,14 @@ import (
"github.com/gofiber/fiber/v2"
)
func ListToStr(l []string) string {
res := ""
for _, e := range l {
res += e+" "
}
return res
}
func RenderError(c *fiber.Ctx, code int) error{
var msg string = "Server Error"
c.Status(code)