Skip to content

Commit

Permalink
feat: use config struct in gobrew
Browse files Browse the repository at this point in the history
  • Loading branch information
juev committed Dec 12, 2023
1 parent 0307901 commit ad444c1
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 26 deletions.
38 changes: 15 additions & 23 deletions gobrew.go
Expand Up @@ -44,17 +44,13 @@ type Command interface {

// GoBrew struct
type GoBrew struct {
rootDir string
installDir string
versionsDir string
currentDir string
currentBinDir string
currentGoDir string
downloadsDir string
registryPathUrl string
gobrewDownloadUrl string
gobrewTags string
gobrewVersionsUrl string
installDir string
versionsDir string
currentDir string
currentBinDir string
currentGoDir string
downloadsDir string
Config
}

type Config struct {
Expand All @@ -69,17 +65,13 @@ type Config struct {
func NewGoBrew(config Config) GoBrew {
installDir := filepath.Join(config.RootDir, goBrewDir)
gb := GoBrew{
rootDir: config.RootDir,
installDir: installDir,
versionsDir: filepath.Join(installDir, "versions"),
currentDir: filepath.Join(installDir, "current"),
currentBinDir: filepath.Join(installDir, "current", "bin"),
currentGoDir: filepath.Join(installDir, "current", "go"),
downloadsDir: filepath.Join(installDir, "downloads"),
registryPathUrl: config.RegistryPathUrl,
gobrewDownloadUrl: config.GobrewDownloadUrl,
gobrewTags: config.GobrewTags,
gobrewVersionsUrl: config.GobrewVersionsUrl,
Config: config,
installDir: installDir,
versionsDir: filepath.Join(installDir, "versions"),
currentDir: filepath.Join(installDir, "current"),
currentBinDir: filepath.Join(installDir, "current", "bin"),
currentGoDir: filepath.Join(installDir, "current", "go"),
downloadsDir: filepath.Join(installDir, "downloads"),
}

return gb
Expand Down Expand Up @@ -348,7 +340,7 @@ func (gb *GoBrew) Upgrade(currentVersion string) {

mkdirTemp, _ := os.MkdirTemp("", "gobrew")
tmpFile := filepath.Join(mkdirTemp, "gobrew"+fileExt)
downloadUrl, _ := url.JoinPath(gb.gobrewDownloadUrl, "gobrew-"+gb.getArch()+fileExt)
downloadUrl, _ := url.JoinPath(gb.GobrewDownloadUrl, "gobrew-"+gb.getArch()+fileExt)
utils.CheckError(
utils.DownloadWithProgress(downloadUrl, "gobrew"+fileExt, mkdirTemp),
"[Error] Download GoBrew failed")
Expand Down
6 changes: 3 additions & 3 deletions helpers.go
Expand Up @@ -316,7 +316,7 @@ func (gb *GoBrew) getVersionDir(version string) string {
func (gb *GoBrew) downloadAndExtract(version string) {
tarName := "go" + version + "." + gb.getArch() + tarNameExt

downloadURL, _ := url.JoinPath(gb.registryPathUrl, tarName)
downloadURL, _ := url.JoinPath(gb.RegistryPathUrl, tarName)
color.Infoln("==> [Info] Downloading from:", downloadURL)

dstDownloadDir := filepath.Join(gb.downloadsDir)
Expand Down Expand Up @@ -359,7 +359,7 @@ func (gb *GoBrew) changeSymblinkGo(version string) {
}

func (gb *GoBrew) getGobrewVersion() string {
data := doRequest(gb.gobrewVersionsUrl)
data := doRequest(gb.GobrewVersionsUrl)
if len(data) == 0 {
return ""
}
Expand All @@ -374,7 +374,7 @@ func (gb *GoBrew) getGobrewVersion() string {
}

func (gb *GoBrew) getGolangVersions() (result []string) {
data := doRequest(gb.gobrewTags)
data := doRequest(gb.GobrewTags)
if len(data) == 0 {
return
}
Expand Down

0 comments on commit ad444c1

Please sign in to comment.