fixed github api limit

This commit is contained in:
2024-05-21 17:05:43 +02:00
parent 064f30fc39
commit 57dfe8a6af
4 changed files with 12 additions and 25 deletions
+5 -4
View File
@@ -23,6 +23,7 @@ type Package struct {
type PackageIndex struct {
Name string `json:"name"`
Repo string `json:"repo"`
Latest string `json:"latest"`
Message string `json:"message"`
}
@@ -48,17 +49,17 @@ func sendRequest(method, url string, jsonBody []byte) Request {
return Request{Body: resBody, StatusCode: res.StatusCode}
}
func getRepoURL(packageName string) (string, error) {
func getPackage(packageName string) (PackageIndex, error) {
var pkgidx PackageIndex
jsonBody := []byte(fmt.Sprintf(`{"name": "%s"}`, packageName))
req := sendRequest(http.MethodGet, "http://localhost:3000", jsonBody)
err := json.Unmarshal(req.Body, &pkgidx)
if err != nil {
fmt.Println("Json Error: ", err)
return "", err
return pkgidx, err
}
if req.StatusCode != 200 {
return "", fmt.Errorf(pkgidx.Message)
return pkgidx, fmt.Errorf(pkgidx.Message)
}
return pkgidx.Repo, nil
return pkgidx, nil
}