package main
import (
- "errors"
+ _ "errors"
"fmt"
"log"
+ "io"
"net"
"net/http"
"net/http/httputil"
"time"
"strings"
"flag"
+ "bytes"
"github.com/spf13/viper"
)
modifyRequest(req)
}
- /*proxy.ModifyResponse = modifyResponse()
- proxy.ErrorHandler = errorHandler()*/
+ proxy.ModifyResponse = modifyResponse()
+ /*proxy.ErrorHandler = errorHandler()*/
return proxy, nil
}
fmt.Println(req.URL)
/* controllo se i file *.go sono cambiati */
+ /* TODO aggiungere i tipi di file da monitorare e anche le sotto-directory */
rebuild := false
dir, _ := os.Open(config.Service.Path)
dirEntries, _ := dir.ReadDir(0)
func modifyResponse() func(*http.Response) error {
return func(resp *http.Response) error {
- return errors.New("response body is invalid")
+ if resp_build.err != nil {
+ //b, _ := io.ReadAll(resp.Body)
+ buf := bytes.NewBufferString(fmt.Sprintf("<pre>STDERR\n%s</pre>", string(resp_build.bStderr.Bytes())))
+ //buf.Write(b)
+ resp.Body = io.NopCloser(buf)
+ resp.Header["Content-Length"] = []string{fmt.Sprint(buf.Len())}
+ }
+
+ //return errors.New("response body is invalid")
+ return nil
}
}
}
}
+type respBuild struct {
+ err error
+ bStdout *bytes.Buffer
+ bStderr *bytes.Buffer
+}
+
+var resp_build respBuild
+
func startApp() {
if pid != 0 {
/* kill app */
return
}
+ resp_build.bStdout = new(bytes.Buffer)
+ resp_build.bStderr = new(bytes.Buffer)
+
cmd := &exec.Cmd {
Dir: config.Service.Path,
Path: goExecPath,
Args: []string{goExecPath, "build", "-o", config.Service.Executable, "."},
- Stdout: os.Stdout,
- Stderr: os.Stdout,
+ Stdout: resp_build.bStdout,
+ Stderr: resp_build.bStderr,
}
- err = cmd.Run()
- if err != nil {
- fmt.Println(err)
+ resp_build.err = cmd.Run()
+ if resp_build.err != nil {
+ fmt.Println("ERR BUILD", resp_build.err)
+ fmt.Println("STDOUT", string(resp_build.bStdout.Bytes()))
+ fmt.Println("STDERR", string(resp_build.bStderr.Bytes()))
}
fmt.Println("ESEGUO RUN")