This repository has been archived by the owner on Dec 29, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
106 lines (83 loc) · 2.04 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
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
package main
import (
"flag"
"fmt"
"log"
"net/http"
"os/exec"
"strings"
"time"
)
// HttpHandler handles requests
type HttpHandler struct {
Dir string
}
// implement `ServeHTTP` method on `HttpHandler` struct
func (h HttpHandler) ServeHTTP(res http.ResponseWriter, req *http.Request) {
url := req.URL.String()
if url == "/cleanup" {
fmt.Println(time.Now().UTC().Format(time.UnixDate) + ": Running e2e clean up")
CleanUp(h, res)
return
}
if strings.Index(url, "/build-exclusions?templateId=") == 0 {
fmt.Println(time.Now().UTC().Format(time.UnixDate) + ": Building template exclusions")
BuildExclusionTree(h, res, req)
return
}
log.Fatalln("No handler found for url: " + url)
}
func CleanUp(h HttpHandler, res http.ResponseWriter) {
cmd := exec.Command("psh", "e2e:cleanup")
cmd.Dir = h.Dir
err := cmd.Run()
if err != nil {
log.Fatal(err)
}
// create response binary data
data := []byte("success")
// write `data` to response
_, err = res.Write(data)
if err != nil {
log.Fatal(err)
}
}
func BuildExclusionTree(h HttpHandler, res http.ResponseWriter, req *http.Request) {
cmd := exec.Command("bin/console", "cupro-template:generate-tree", req.URL.Query().Get("templateId"))
cmd.Dir = h.Dir
err := cmd.Run()
if err != nil {
log.Fatal(err)
}
// create response binary data
data := []byte("success")
// write `data` to response
_, err = res.Write(data)
if err != nil {
log.Fatal(err)
}
}
func main() {
pathPointer := flag.String("path", "", "Path to your shopware installation")
flag.Parse()
if len([]rune(*pathPointer)) == 0 {
log.Fatal("Please specify a path with -path=/my/path")
}
fmt.Println("Starting in: " + *pathPointer)
fmt.Println("Creating db dump")
cmd := exec.Command("psh", "e2e:dump-db")
cmd.Dir = *pathPointer
err := cmd.Run()
if err != nil {
log.Fatal(err)
}
// create a new handler
handler := HttpHandler{}
handler.Dir = *pathPointer
fmt.Println("Listening on port 8005")
// listen and serve
err = http.ListenAndServe(":8005", handler)
if err != nil {
log.Fatal(err)
}
}