-
Notifications
You must be signed in to change notification settings - Fork 0
/
handlers.go
41 lines (38 loc) · 745 Bytes
/
handlers.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
package main
import (
"fmt"
"github.com/google/uuid"
"io"
"os/exec"
"time"
)
func deployer(repo Repository) (string, error) {
id := uuid.New()
return id.String(), executor(id.String(), repo)
}
func executor(uuid string, repo Repository) error {
fmt.Println("executor initiating")
cmd := exec.Command(SCRIPT)
stderr, err := cmd.StderrPipe()
stdout, err := cmd.StdoutPipe()
if err != nil {
return err
}
if err := cmd.Start(); err != nil {
return err
}
results, _ := io.ReadAll(stdout)
errors, _ := io.ReadAll(stderr)
d := Deployment{
ID: uuid,
StdOut: results,
StdErr: errors,
Time: time.Now().String(),
}
fmt.Println(results)
err = repo.InsertDeployment(d)
if err != nil {
return err
}
return nil
}