This repository has been archived by the owner on Jul 30, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
golang.go
80 lines (61 loc) · 1.73 KB
/
golang.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
package templates
import (
"fmt"
"log"
"os"
"os/exec"
"path/filepath"
"runtime"
"github.com/abdfnx/botway/constants"
"github.com/abdfnx/looker"
)
func MainGoContent(platform string) string {
return Content("main.go", platform+"-go", "", "")
}
func GoTemplate(botName, platform string) {
goPath, err := looker.LookPath("go")
if err != nil {
fmt.Print(constants.FAIL_BACKGROUND.Render("ERROR"))
fmt.Println(constants.FAIL_FOREGROUND.Render(" go is not installed"))
} else {
goInit := goPath + " mod init " + botName
cmd := exec.Command("bash", "-c", goInit)
if runtime.GOOS == "windows" {
cmd = exec.Command("powershell.exe", goInit)
}
cmd.Dir = botName
cmd.Stdin = os.Stdin
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
err = cmd.Run()
if err != nil {
log.Printf("error: %v\n", err)
}
mainFile := os.WriteFile(filepath.Join(botName, "src", "main.go"), []byte(MainGoContent(platform)), 0644)
dockerFile := os.WriteFile(filepath.Join(botName, "Dockerfile"), []byte(DockerfileContent(botName, "go.dockerfile", platform)), 0644)
resourcesFile := os.WriteFile(filepath.Join(botName, "resources.md"), []byte(Resources(platform, "go.md")), 0644)
if mainFile != nil {
log.Fatal(mainFile)
}
if dockerFile != nil {
log.Fatal(dockerFile)
}
if resourcesFile != nil {
log.Fatal(resourcesFile)
}
goTidy := goPath + " mod tidy"
tidyCmd := exec.Command("bash", "-c", goTidy)
if runtime.GOOS == "windows" {
tidyCmd = exec.Command("powershell.exe", goTidy)
}
tidyCmd.Dir = botName
tidyCmd.Stdin = os.Stdin
tidyCmd.Stdout = os.Stdout
tidyCmd.Stderr = os.Stderr
err = tidyCmd.Run()
if err != nil {
log.Printf("error: %v\n", err)
}
CheckProject(botName, platform)
}
}