-
-
Notifications
You must be signed in to change notification settings - Fork 20
/
launcher.go
executable file
·133 lines (101 loc) · 3.04 KB
/
launcher.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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
// File generated by Gopher Sauce
// DO NOT EDIT!!
package main
import (
"fmt"
"log"
"os"
"path/filepath"
"runtime"
"strings"
"github.com/cheikhshift/gos/core"
"github.com/ncruces/rethinkraw/pkg/chrome"
"github.com/thestrukture/IDE/api/globals"
"github.com/thestrukture/IDE/api/methods"
"github.com/thestrukture/IDE/types"
)
func LaunchServer() {
globals.Dfd = os.ExpandEnv("$GOPATH")
globals.Windows = strings.Contains(runtime.GOOS, "windows")
trailerEx := ""
fmt.Println("Using $GOPATH @ home/workspace")
if globals.Windows {
os.Chdir(os.ExpandEnv("$USERPROFILE"))
trailerEx = ".exe"
} else {
os.Chdir(os.ExpandEnv("$HOME"))
}
err := os.MkdirAll("workspace/", 0700)
if err != nil {
fmt.Println(err.Error())
} else {
//download go
os.MkdirAll("workspace/src", 0700)
os.MkdirAll("workspace/bin", 0700)
os.MkdirAll("workspace/cache", 0700)
os.MkdirAll("workspace/userData", 0700)
cwd, _ := os.Getwd()
cwd = cwd + "/workspace"
os.Setenv("GOPATH", cwd)
pathbin := os.ExpandEnv("$PATH")
if globals.Windows {
os.Setenv("PATH", pathbin+":"+strings.Replace(cwd+"/bin", "/", "\\", -1))
} else {
os.Setenv("PATH", pathbin+":"+cwd+"/bin")
}
globals.Dfd = cwd
}
if _, err := os.Stat(os.ExpandEnv("$GOPATH") + "/bin/gocode" + trailerEx); os.IsNotExist(err) {
fmt.Println("Go code completion not present, installing from github.com/mdempsky/gocode")
if globals.Windows {
//
core.RunCmdSmart("go get -u -ldflags -H=windowsgui github.com/mdempsky/gocode")
} else {
_, err1 := core.RunCmdSmart("go install github.com/mdempsky/gocode@latest")
if err1 != nil {
log.Fatal(err1)
}
}
}
if _, err := os.Stat(os.ExpandEnv("$GOPATH") + "/bin/dlv" + trailerEx); os.IsNotExist(err) {
fmt.Println("Delve not present, installing from github.com/go-delve/delve/cmd/dlv")
_, err1 := core.RunCmdSmart("go install github.com/go-delve/delve/cmd/dlv@latest")
if err1 != nil {
log.Fatal(err1)
}
}
if _, err := os.Stat(os.ExpandEnv("$GOPATH") + "/bin/golint" + trailerEx); os.IsNotExist(err) {
fmt.Println("Golint not present, installing from golang.org/x/lint/golint")
_, err1 := core.RunCmdSmart("go install golang.org/x/lint/golint@latest")
if err1 != nil {
log.Fatal(err1)
}
}
globals.AutocompletePath = filepath.Join(os.ExpandEnv("$GOPATH"), "strukture-autocomplete")
if _, err := os.Stat(globals.AutocompletePath); os.IsNotExist(err) {
fmt.Println("Creating autocomplete resource folder at " + globals.AutocompletePath)
os.MkdirAll(globals.AutocompletePath, 0700)
}
apps := methods.GetApps()
newapps := []types.App{}
for _, app := range apps {
if app.Name != "" {
app.Pid = ""
newapps = append(newapps, app)
}
}
methods.SaveApps(newapps)
log.Println("Strukture up on port 8884")
if len(os.Args) == 1 {
go func() {
dataDir := filepath.Join(globals.Dfd, "userData")
cache := filepath.Join(globals.Dfd, "cache")
c := chrome.Command("http://localhost:8884", dataDir, cache)
err := c.Run()
if err != nil {
log.Fatal(err)
}
os.Exit(0)
}()
}
}