mirror of
https://github.com/engineer-man/piston.git
synced 2025-09-20 10:50:04 +02:00
Update main.go
This commit is contained in:
parent
a14a810925
commit
478aca1cea
1 changed files with 101 additions and 102 deletions
23
api/main.go
23
api/main.go
|
@ -5,12 +5,11 @@ import (
|
|||
"encoding/json"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"log"
|
||||
"net/http"
|
||||
"os"
|
||||
"os/exec"
|
||||
"strings"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
|
@ -48,9 +47,7 @@ func main() {
|
|||
fmt.Println("starting api on port", port)
|
||||
|
||||
http.HandleFunc("/execute", Execute)
|
||||
err := http.ListenAndServe(fmt.Sprintf("0.0.0.0:%d", port), nil); if err != nil{
|
||||
log.Fatal(err)
|
||||
}
|
||||
http.ListenAndServe(fmt.Sprintf("0.0.0.0:%d", port), nil)
|
||||
}
|
||||
|
||||
func Execute(res http.ResponseWriter, req *http.Request) {
|
||||
|
@ -90,8 +87,9 @@ func Execute(res http.ResponseWriter, req *http.Request) {
|
|||
Message: inbound.Language + " is not supported by Piston",
|
||||
}
|
||||
|
||||
pres, err := json.Marshal(problem); if err != nil{
|
||||
log.Fatal(err)
|
||||
pres, err := json.Marshal(problem)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
}
|
||||
|
||||
res.Write(pres)
|
||||
|
@ -126,10 +124,10 @@ func launch(request inbound, res http.ResponseWriter) {
|
|||
cmd.Stdout = &stdout
|
||||
cmd.Stderr = &stderr
|
||||
|
||||
err := cmd.Run(); if err != nil{
|
||||
log.Fatal(err)
|
||||
err := cmd.Run()
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
}
|
||||
|
||||
// prepare response
|
||||
outbound := outbound{
|
||||
Generator: fmt.Sprintf("docker-%d", instance),
|
||||
|
@ -137,8 +135,9 @@ func launch(request inbound, res http.ResponseWriter) {
|
|||
Output: strings.TrimSpace(stdout.String()),
|
||||
}
|
||||
|
||||
response, err:= json.Marshal(outbound); if err != nil{
|
||||
log.Fatal(err)
|
||||
response, err := json.Marshal(outbound)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
}
|
||||
|
||||
res.Write(response)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue