-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.go
77 lines (73 loc) · 2.09 KB
/
main.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
package main
import (
"VirtualMachineHandler/helpers"
"VirtualMachineHandler/vmware/actions"
"encoding/json"
"fmt"
"log"
"net/http"
"net/http/httputil"
)
func main() {
helpers.InitConfig()
helpers.CompileRegexes()
http.HandleFunc("/env", actions.Env)
http.HandleFunc("/create", func(w http.ResponseWriter, req *http.Request) {
uuid := helpers.GenerateUUID()
_, _ = fmt.Fprint(w, uuid)
body := helpers.Create{}
err := json.NewDecoder(req.Body).Decode(&body)
if err != nil {
log.Println(err.Error())
}
go actions.Create(body, uuid)
})
http.HandleFunc("/delete", func(w http.ResponseWriter, req *http.Request) {
uuid := helpers.GenerateUUID()
_, _ = fmt.Fprint(w, uuid)
body := helpers.Delete{}
err := json.NewDecoder(req.Body).Decode(&body)
if err != nil {
log.Println(err.Error())
}
go func() {
_ = actions.Delete(body.LocationId, body.TargetName, uuid)
}()
})
http.HandleFunc("/recreate", func(w http.ResponseWriter, req *http.Request) {
uuid := helpers.GenerateUUID()
_, _ = fmt.Fprint(w, uuid)
body := helpers.Create{}
err := json.NewDecoder(req.Body).Decode(&body)
if err != nil {
log.Println(err.Error())
}
go actions.Recreate(body, uuid)
})
http.HandleFunc("/update", func(w http.ResponseWriter, req *http.Request) {
uuid := helpers.GenerateUUID()
_, _ = fmt.Fprint(w, uuid)
body := helpers.Update{}
err := json.NewDecoder(req.Body).Decode(&body)
if err != nil {
log.Println(err.Error())
}
go actions.Update(body, uuid)
})
http.HandleFunc("/changeState", func(w http.ResponseWriter, req *http.Request) {
uuid := helpers.GenerateUUID()
_, _ = fmt.Fprint(w, uuid)
body := helpers.State{}
err := json.NewDecoder(req.Body).Decode(&body)
if err != nil {
log.Println(err.Error())
}
go actions.ChangeState(body, uuid)
})
http.HandleFunc("/dump", func(w http.ResponseWriter, req *http.Request) {
dump, _ := httputil.DumpRequest(req, true)
log.Println(string(dump))
})
log.Printf("server is listening at port %s", helpers.Config.HttpPort)
log.Fatal(http.ListenAndServe(fmt.Sprintf(":%s", helpers.Config.HttpPort), nil))
}