-
Notifications
You must be signed in to change notification settings - Fork 0
/
invoke.go
43 lines (40 loc) · 976 Bytes
/
invoke.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
package main
import (
"fmt"
"io/ioutil"
"log"
"net/http"
"os"
"os/exec"
)
func main() {
http.HandleFunc("/", callRocco)
port := os.Getenv("PORT")
if port == "" {
port = "8080"
log.Printf("Defaulting to port %s", port)
}
log.Printf("Listening on port %s", port)
if err := http.ListenAndServe(":"+port, nil); err != nil {
log.Fatal(err)
}
}
func callRocco(w http.ResponseWriter, r *http.Request) {
b, err := ioutil.ReadAll(r.Body)
if err != nil {
panic(err)
}
cmd := exec.CommandContext(
r.Context(),
"/app/rocco",
"post",
"--payload",
fmt.Sprintf("'%s'", string(b[:])),
)
cmd.Stderr = os.Stderr
out, err := cmd.Output()
if err != nil {
w.WriteHeader(500)
}
w.Write(out)
}