Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
nothub committed Sep 2, 2022
1 parent aef2c71 commit 1661b61
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 17 deletions.
27 changes: 26 additions & 1 deletion cmd/install.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
package cmd

import (
"github.com/nothub/gorinth/http"
"github.com/spf13/cobra"
"log"
"net/url"
"os"
)

func init() {
Expand All @@ -15,6 +18,28 @@ var installCmd = &cobra.Command{
Long: `TODO`,

Run: func(cmd *cobra.Command, args []string) {
log.Fatalln("Not yet implemented!")
if len(args) < 1 {
// TODO: cobra arg checks
log.Fatalln("argghh")
}

if _, err := os.Stat(args[0]); err == nil {
// arg is existing file path

} else if _, err := url.Parse(args[0]); err != nil {
// arg is valid url

file, err := http.Instance.DownloadFile(args[0], ".")
if err != nil {
log.Fatalln(err)
}
log.Println("Stored mrpack to:", file)

} else {
// arg is project id?
// TODO
}

// TODO
},
}
4 changes: 2 additions & 2 deletions http/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ func init() {
}
}

func (client *Client) GetJson(url string, body io.Reader, respModel interface{}, errModel ErrorModel) error {
request, err := http.NewRequest(http.MethodGet, url, body)
func (client *Client) GetJson(url string, respModel interface{}, errModel ErrorModel) error {
request, err := http.NewRequest(http.MethodGet, url, nil)
if err != nil {
return err
}
Expand Down
20 changes: 10 additions & 10 deletions modrinth/api/endpoints.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ func (client *ApiClient) LabrinthInfo() (*LabrinthInfo, error) {
}

labrinthInfo := LabrinthInfo{}
err = client.Http.GetJson(url.String(), nil, &labrinthInfo, &Error{})
err = client.Http.GetJson(url.String(), &labrinthInfo, &Error{})
if err != nil {
return nil, err
}
Expand All @@ -32,7 +32,7 @@ func (client *ApiClient) GetProject(id string) (*Project, error) {
}

project := Project{}
err = client.Http.GetJson(url.String(), nil, &project, &Error{})
err = client.Http.GetJson(url.String(), &project, &Error{})
if err != nil {
return nil, err
}
Expand All @@ -52,7 +52,7 @@ func (client *ApiClient) GetProjects(ids []string) ([]*Project, error) {
url.RawQuery = query.Encode()

var projects []*Project
err = client.Http.GetJson(url.String(), nil, &projects, &Error{})
err = client.Http.GetJson(url.String(), &projects, &Error{})
if err != nil {
return nil, err
}
Expand All @@ -68,7 +68,7 @@ func (client *ApiClient) CheckProjectValidity(id string) (*CheckResponse, error)
}

var checkResponse CheckResponse
err = client.Http.GetJson(url.String(), nil, &checkResponse, &Error{})
err = client.Http.GetJson(url.String(), &checkResponse, &Error{})
if err != nil {
return nil, err
}
Expand All @@ -84,7 +84,7 @@ func (client *ApiClient) GetDependencies(id string) (*Dependencies, error) {
}

var dependencies Dependencies
err = client.Http.GetJson(url.String(), nil, &dependencies, &Error{})
err = client.Http.GetJson(url.String(), &dependencies, &Error{})
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -114,7 +114,7 @@ func (client *ApiClient) GetProjectVersions(id string, params *GetProjectVersion
url.RawQuery = query.Encode()

var versions []*Version
err = client.Http.GetJson(url.String(), nil, &versions, &Error{})
err = client.Http.GetJson(url.String(), &versions, &Error{})
if err != nil {
return nil, err
}
Expand All @@ -136,7 +136,7 @@ func (client *ApiClient) GetVersion(id string) (*Version, error) {
}

var version Version
err = client.Http.GetJson(url.String(), nil, &version, &Error{})
err = client.Http.GetJson(url.String(), &version, &Error{})
if err != nil {
return nil, err
}
Expand All @@ -156,7 +156,7 @@ func (client *ApiClient) GetVersions(ids []string) ([]*Version, error) {
url.RawQuery = query.Encode()

var versions []*Version
err = client.Http.GetJson(url.String(), nil, &versions, &Error{})
err = client.Http.GetJson(url.String(), &versions, &Error{})
if err != nil {
return nil, err
}
Expand All @@ -178,7 +178,7 @@ func (client *ApiClient) VersionFromHash(hash string, algorithm HashAlgo) (*Vers
url.RawQuery = query.Encode()

var version *Version
err = client.Http.GetJson(url.String(), nil, &version, &Error{})
err = client.Http.GetJson(url.String(), &version, &Error{})
if err != nil {
return nil, err
}
Expand All @@ -194,7 +194,7 @@ func (client *ApiClient) GetLatestGameVersion() (string, error) {
}

var gameVersions []*GameVersion
err = client.Http.GetJson(url.String(), nil, &gameVersions, &Error{})
err = client.Http.GetJson(url.String(), &gameVersions, &Error{})
if err != nil {
return "", err
}
Expand Down
2 changes: 1 addition & 1 deletion mojang/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ func LatestVersion() (string, error) {
Snapshot string `json:"snapshot"`
} `json:"latest"`
}
err := http.Instance.GetJson(manifestUrl, nil, &manifest, nil)
err := http.Instance.GetJson(manifestUrl, &manifest, nil)
if err != nil {
return "", err
}
Expand Down
4 changes: 2 additions & 2 deletions server/fabric.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func latestFabricLoaderVersion(mcVer string) (string, error) {
Stable bool `json:"stable"`
} `json:"loader"`
}
err := http.Instance.GetJson("https://meta.fabricmc.net/v2/versions/loader/"+mcVer, nil, &loaders, nil)
err := http.Instance.GetJson("https://meta.fabricmc.net/v2/versions/loader/"+mcVer, &loaders, nil)
if err != nil {
return "", err
}
Expand All @@ -59,7 +59,7 @@ func latestFabricInstallerVersion() (string, error) {
Version string `json:"version"`
Stable bool `json:"stable"`
}
err := http.Instance.GetJson("https://meta.fabricmc.net/v2/versions/installer", nil, &installers, nil)
err := http.Instance.GetJson("https://meta.fabricmc.net/v2/versions/installer", &installers, nil)
if err != nil {
return "", err
}
Expand Down
2 changes: 1 addition & 1 deletion server/paper.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ func (supplier *Paper) GetUrl() (string, error) {
} `json:"downloads"`
} `json:"builds"`
}
err := http.Instance.GetJson("https://api.papermc.io/v2/projects/paper/versions/"+supplier.MinecraftVersion+"/builds", nil, &response, nil)
err := http.Instance.GetJson("https://api.papermc.io/v2/projects/paper/versions/"+supplier.MinecraftVersion+"/builds", &response, nil)
if err != nil {
return "", err
}
Expand Down

0 comments on commit 1661b61

Please sign in to comment.