Update main.go

This commit is contained in:
Mark Joling 2018-10-10 15:50:36 +02:00 committed by GitHub
parent a14a810925
commit 478aca1cea
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -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)