refactor: seperate functionality into files
This commit is contained in:
parent
715e086fcd
commit
3081e34e2b
11 changed files with 871 additions and 792 deletions
67
utils.go
Normal file
67
utils.go
Normal file
|
|
@ -0,0 +1,67 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io"
|
||||
"net/http"
|
||||
"os"
|
||||
"runtime"
|
||||
|
||||
"github.com/charmbracelet/huh"
|
||||
)
|
||||
|
||||
func getSudoPassword() (string, error) {
|
||||
var password string
|
||||
form := huh.NewForm(
|
||||
huh.NewGroup(
|
||||
huh.NewInput().
|
||||
Title("Bitte geben Sie Ihr sudo-Passwort ein").
|
||||
EchoMode(huh.EchoModePassword).
|
||||
Value(&password),
|
||||
),
|
||||
).WithTheme(huh.ThemeCatppuccin())
|
||||
|
||||
err := form.Run()
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("Fehler bei der Passwortabfrage: %v", err)
|
||||
}
|
||||
return password, nil
|
||||
}
|
||||
|
||||
func downloadGolang(golangVersion string) error {
|
||||
var link string
|
||||
if runtime.GOARCH == "arm64" {
|
||||
link = "https://go.dev/dl/go" + golangVersion + ".linux-arm64.tar.gz"
|
||||
} else {
|
||||
link = "https://go.dev/dl/go" + golangVersion + ".linux-amd64.tar.gz"
|
||||
}
|
||||
resp, err := http.Get(link)
|
||||
if err != nil {
|
||||
return fmt.Errorf("Fehler beim Herunterladen von Go: %v", err)
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
|
||||
if resp.StatusCode != http.StatusOK {
|
||||
return fmt.Errorf("Unerwarteter HTTP-Status: %s", resp.Status)
|
||||
}
|
||||
|
||||
outFile, err := os.Create("go" + golangVersion + ".linux-" + runtime.GOARCH + ".tar.gz")
|
||||
if err != nil {
|
||||
return fmt.Errorf("Fehler beim Erstellen der Ausgabedatei: %v", err)
|
||||
}
|
||||
defer outFile.Close()
|
||||
|
||||
_, err = io.Copy(outFile, resp.Body)
|
||||
if err != nil {
|
||||
return fmt.Errorf("Fehler beim Schreiben der Ausgabedatei: %v", err)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func max(a, b int) int {
|
||||
if a > b {
|
||||
return a
|
||||
}
|
||||
return b
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue