Skip to content

Commit 951a0a1

Browse files
committed
formatting
1 parent 8e2356b commit 951a0a1

File tree

1 file changed

+37
-35
lines changed

1 file changed

+37
-35
lines changed

proxy/util.go

+37-35
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package proxy
33
import (
44
"bytes"
55
"fmt"
6+
"io"
67
"io/ioutil"
78
"log"
89
"net"
@@ -12,47 +13,48 @@ import (
1213
"regexp"
1314
"strings"
1415
"sync"
16+
"syscall"
1517
"unicode"
1618
)
1719

1820
var haProxyCmd = "haproxy"
1921

2022
var cmdRunHa = func(args []string) error {
21-
var stdoutBuf, stderrBuf bytes.Buffer
22-
cmd := exec.Command(haProxyCmd, args...)
23-
24-
stdoutIn, _ := cmd.StdoutPipe()
25-
stderrIn, _ := cmd.StderrPipe()
26-
27-
stdout := io.MultiWriter(os.Stdout, &stdoutBuf)
28-
stderr := io.MultiWriter(os.Stderr, &stderrBuf)
29-
cmd.Start()
30-
31-
go func() {
32-
io.Copy(stdout, stdoutIn)
33-
}()
34-
35-
go func() {
36-
io.Copy(stderr, stderrIn)
37-
}()
38-
39-
err := cmd.Wait()
40-
41-
outStr, errStr := string(stdoutBuf.Bytes()), string(stderrBuf.Bytes())
42-
combinedOut := fmt.Sprintf("\nstdout:\n%s\nstderr:\n%s\n", outStr, errStr)
43-
44-
if exitError, ok := err.(*exec.ExitError); ok {
45-
waitStatus := exitError.Sys().(syscall.WaitStatus)
46-
fmt.Printf("Exit Status: %s\n", []byte(fmt.Sprintf("%d", waitStatus.ExitStatus())))
47-
return fmt.Errorf(combinedOut)
48-
}
49-
50-
if errStr != "" {
51-
fmt.Println("The configuration file is valid, but there still may be a misconfiguration",
52-
"somewhere that will give unexpected results, please verify:", combinedOut)
53-
}
54-
55-
return nil
23+
var stdoutBuf, stderrBuf bytes.Buffer
24+
cmd := exec.Command(haProxyCmd, args...)
25+
26+
stdoutIn, _ := cmd.StdoutPipe()
27+
stderrIn, _ := cmd.StderrPipe()
28+
29+
stdout := io.MultiWriter(os.Stdout, &stdoutBuf)
30+
stderr := io.MultiWriter(os.Stderr, &stderrBuf)
31+
cmd.Start()
32+
33+
go func() {
34+
io.Copy(stdout, stdoutIn)
35+
}()
36+
37+
go func() {
38+
io.Copy(stderr, stderrIn)
39+
}()
40+
41+
err := cmd.Wait()
42+
43+
outStr, errStr := string(stdoutBuf.Bytes()), string(stderrBuf.Bytes())
44+
combinedOut := fmt.Sprintf("\nstdout:\n%s\nstderr:\n%s\n", outStr, errStr)
45+
46+
if exitError, ok := err.(*exec.ExitError); ok {
47+
waitStatus := exitError.Sys().(syscall.WaitStatus)
48+
fmt.Printf("Exit Status: %s\n", []byte(fmt.Sprintf("%d", waitStatus.ExitStatus())))
49+
return fmt.Errorf(combinedOut)
50+
}
51+
52+
if errStr != "" {
53+
fmt.Println("The configuration file is valid, but there still may be a misconfiguration",
54+
"somewhere that will give unexpected results, please verify:", combinedOut)
55+
}
56+
57+
return nil
5658
}
5759

5860
var cmdValidateHa = func(args []string) error {

0 commit comments

Comments
 (0)