-
-
Notifications
You must be signed in to change notification settings - Fork 20
/
rest_POSTApiPut.go
executable file
·192 lines (139 loc) · 7.32 KB
/
rest_POSTApiPut.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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
// File generated by Gopher Sauce
// DO NOT EDIT!!
package handlers
import (
"crypto/sha512"
"io/ioutil"
"net/http"
"os"
"path/filepath"
"github.com/cheikhshift/gos/core"
"github.com/gorilla/sessions"
templates "github.com/thestrukture/IDE/api/templates"
types "github.com/thestrukture/IDE/types"
)
//
func POSTApiPut(w http.ResponseWriter, r *http.Request, session *sessions.Session) (response string, callmet bool) {
me := types.SoftUser{Email: "Strukture user", Username: "Strukture user"}
if r.FormValue("type") == "0" {
//fmt.Println(m)
gos, _ := core.PLoadGos(os.ExpandEnv("$GOPATH") + "/src/" + r.FormValue("id") + "/gos.gxml")
gos.Set(r.FormValue("put"), r.FormValue("var"))
// fmt.Println(gos)
gos.PSaveGos(os.ExpandEnv("$GOPATH") + "/src/" + r.FormValue("id") + "/gos.gxml")
} else if r.FormValue("type") == "1" {
ioutil.WriteFile(os.ExpandEnv("$GOPATH")+"/src/"+r.FormValue("pkg")+"/"+r.FormValue("target"), []byte(r.FormValue("data")), 0644)
response = templates.Alert(types.Alertbs{Type: "warning", Text: r.FormValue("target") + " saved!"})
} else if r.FormValue("type") == "2" {
gos, _ := core.PLoadGos(os.ExpandEnv("$GOPATH") + "/src/" + r.FormValue("pkg") + "/gos.gxml")
gos.Update("template", r.FormValue("id"), r.FormValue("struct"))
// fmt.Println(gos)
gos.PSaveGos(os.ExpandEnv("$GOPATH") + "/src/" + r.FormValue("pkg") + "/gos.gxml")
response = "Template interface saved!"
} else if r.FormValue("type") == "3" {
ioutil.WriteFile(os.ExpandEnv("$GOPATH")+"/src/"+r.FormValue("pkg")+"/web"+r.FormValue("target"), []byte(r.FormValue("data")), 0777)
response = templates.Alert(types.Alertbs{Type: "warning", Text: r.FormValue("target") + " saved!"})
} else if r.FormValue("type") == "30" {
ioutil.WriteFile(os.ExpandEnv("$GOPATH")+"/src/"+filepath.Join(r.FormValue("pkg"), r.FormValue("target")), []byte(r.FormValue("data")), 0777)
response = templates.Alert(types.Alertbs{Type: "warning", Text: r.FormValue("target") + " saved!"})
} else if r.FormValue("type") == "4" {
filep := os.ExpandEnv("$GOPATH") + "/src/" + r.FormValue("pkg") + "/structs.dsl"
gos, _ := core.PLoadGos(os.ExpandEnv("$GOPATH") + "/src/" + r.FormValue("pkg") + "/gos.gxml")
//write file
ioutil.WriteFile(filep, []byte(r.FormValue("data")), 0644)
//marhal and add
vgos := core.CreateVGos(filep)
//fmt.Println(vgos,"Gos")
gos.MStructs(vgos.Structs)
gos.PSaveGos(os.ExpandEnv("$GOPATH") + "/src/" + r.FormValue("pkg") + "/gos.gxml")
response = templates.Alert(types.Alertbs{Type: "warning", Text: "Interfaces saved!"})
} else if r.FormValue("type") == "5" {
filep := os.ExpandEnv("$GOPATH") + "/src/" + r.FormValue("pkg") + "/objects.dsl"
gos, _ := core.PLoadGos(os.ExpandEnv("$GOPATH") + "/src/" + r.FormValue("pkg") + "/gos.gxml")
//write file
ioutil.WriteFile(filep, []byte(r.FormValue("data")), 0644)
//marhal and add
vgos := core.CreateVGos(filep)
//fmt.Println(vgos,"Gos")
gos.MObjects(vgos.Objects)
gos.PSaveGos(os.ExpandEnv("$GOPATH") + "/src/" + r.FormValue("pkg") + "/gos.gxml")
response = templates.Alert(types.Alertbs{Type: "warning", Text: "Objects saved!"})
} else if r.FormValue("type") == "6" {
filep := os.ExpandEnv("$GOPATH") + "/src/" + r.FormValue("pkg") + "/methods.dsl"
gos, _ := core.PLoadGos(os.ExpandEnv("$GOPATH") + "/src/" + r.FormValue("pkg") + "/gos.gxml")
//write file
ioutil.WriteFile(filep, []byte(r.FormValue("data")), 0644)
//marhal and add
vgos := core.CreateVGos(filep)
//fmt.Println(vgos,"Gos")
gos.MMethod(vgos.Methods)
gos.PSaveGos(os.ExpandEnv("$GOPATH") + "/src/" + r.FormValue("pkg") + "/gos.gxml")
response = templates.Alert(types.Alertbs{Type: "warning", Text: "Pipelines saved!"})
} else if r.FormValue("type") == "7" {
gos, _ := core.PLoadGos(os.ExpandEnv("$GOPATH") + "/src/" + r.FormValue("space") + "/gos.gxml")
//write file
gos.Add("end", "", r.FormValue("path"))
gos.PSaveGos(os.ExpandEnv("$GOPATH") + "/src/" + r.FormValue("space") + "/gos.gxml")
} else if r.FormValue("type") == "8" {
gos, _ := core.PLoadGos(os.ExpandEnv("$GOPATH") + "/src/" + r.FormValue("space") + "/gos.gxml")
//write file
gos.Add("timer", "", r.FormValue("name"))
gos.PSaveGos(os.ExpandEnv("$GOPATH") + "/src/" + r.FormValue("space") + "/gos.gxml")
} else if r.FormValue("type") == "9" {
gos, _ := core.PLoadGos(os.ExpandEnv("$GOPATH") + "/src/" + r.FormValue("pkg") + "/gos.gxml")
//write file
gos.Update("end", r.FormValue("id"), core.Endpoint{Path: r.FormValue("path"), Type: r.FormValue("typ")})
gos.PSaveGos(os.ExpandEnv("$GOPATH") + "/src/" + r.FormValue("pkg") + "/gos.gxml")
response = "OK"
} else if r.FormValue("type") == "13r" {
gos, _ := core.PLoadGos(os.ExpandEnv("$GOPATH") + "/src/" + r.FormValue("pkg") + "/gos.gxml")
//write file
gos.UpdateMethod(r.FormValue("target"), r.FormValue("data"))
gos.PSaveGos(os.ExpandEnv("$GOPATH") + "/src/" + r.FormValue("pkg") + "/gos.gxml")
response = templates.Alert(types.Alertbs{Type: "warning", Text: "Endpoint code saved!"})
} else if r.FormValue("type") == "10" {
gos, _ := core.PLoadGos(os.ExpandEnv("$GOPATH") + "/src/" + r.FormValue("pkg") + "/gos.gxml")
//write file
gos.Update("timer", r.FormValue("id"), core.Timer{Name: r.FormValue("name"), Method: r.FormValue("method"), Unit: r.FormValue("unit"), Interval: r.FormValue("interval")})
gos.PSaveGos(os.ExpandEnv("$GOPATH") + "/src/" + r.FormValue("pkg") + "/gos.gxml")
response = "OK"
} else if r.FormValue("type") == "11" {
hasher := sha512.New512_256()
if string(hasher.Sum([]byte(r.FormValue("cpassword")))) == string(me.Password) {
me.Password = hasher.Sum([]byte(r.FormValue("npassword")))
response = templates.Alert(types.Alertbs{Type: "success", Text: "Password updated"})
} else {
response = templates.Alert(types.Alertbs{Type: "danger", Text: "Error incorrect current password"})
}
} else if r.FormValue("type") == "12" {
me.Email = r.FormValue("email")
response = templates.Alert(types.Alertbs{Type: "success", Text: "Email updated"})
} else if r.FormValue("type") == "13" {
gos, _ := core.PLoadGos(os.ExpandEnv("$GOPATH") + "/src/" + r.FormValue("pkg") + "/gos.gxml")
//write file
gos.Main = r.FormValue("data")
gos.PSaveGos(os.ExpandEnv("$GOPATH") + "/src/" + r.FormValue("pkg") + "/gos.gxml")
} else if r.FormValue("type") == "14" {
gos, _ := core.PLoadGos(os.ExpandEnv("$GOPATH") + "/src/" + r.FormValue("pkg") + "/gos.gxml")
//write file
gos.Init_Func = r.FormValue("data")
gos.PSaveGos(os.ExpandEnv("$GOPATH") + "/src/" + r.FormValue("pkg") + "/gos.gxml")
} else if r.FormValue("type") == "15" {
gos, _ := core.PLoadGos(os.ExpandEnv("$GOPATH") + "/src/" + r.FormValue("pkg") + "/gos.gxml")
//write file
gos.Session = r.FormValue("data")
gos.PSaveGos(os.ExpandEnv("$GOPATH") + "/src/" + r.FormValue("pkg") + "/gos.gxml")
} else if r.FormValue("type") == "16" {
gos, _ := core.PLoadGos(os.ExpandEnv("$GOPATH") + "/src/" + r.FormValue("pkg") + "/gos.gxml")
//write file
gos.Package = r.FormValue("var")
gos.PSaveGos(os.ExpandEnv("$GOPATH") + "/src/" + r.FormValue("pkg") + "/gos.gxml")
} else if r.FormValue("type") == "17" {
gos, _ := core.PLoadGos(os.ExpandEnv("$GOPATH") + "/src/" + r.FormValue("pkg") + "/gos.gxml")
//write file
gos.Shutdown = r.FormValue("data")
gos.PSaveGos(os.ExpandEnv("$GOPATH") + "/src/" + r.FormValue("pkg") + "/gos.gxml")
}
callmet = true
return
}