Skip to content
Snippets Groups Projects
Commit b11c4004 authored by Alex's avatar Alex
Browse files

Combine stdout/stderr (experimental)

Don't panic on error, keep alive and return 500.
parent 33a8f012
No related branches found
No related tags found
No related merge requests found
package main
import (
"bytes"
"io/ioutil"
"log"
"net/http"
......@@ -20,18 +21,31 @@ func main() {
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
if r.Method == "POST" {
process := os.Getenv("fprocess")
parts := strings.Split(process, " ")
targetCmd := exec.Command(parts[0], parts[1:]...)
writer, _ := targetCmd.StdinPipe()
res, _ := ioutil.ReadAll(r.Body)
writer.Write(res)
writer.Close()
out, err := targetCmd.Output()
targetCmd.CombinedOutput()
if err != nil {
panic(err)
log.Println(targetCmd, err)
w.WriteHeader(500)
response := bytes.NewBufferString(err.Error())
w.Write(response.Bytes())
return
}
w.WriteHeader(200)
// TODO: consider stdout to container as configurable via env-variable.
os.Stdout.Write(out)
w.Write(out)
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment