Skip to content

Commit

Permalink
formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
vfarcic committed Dec 2, 2017
1 parent 8e2356b commit 951a0a1
Showing 1 changed file with 37 additions and 35 deletions.
72 changes: 37 additions & 35 deletions proxy/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package proxy
import (
"bytes"
"fmt"
"io"
"io/ioutil"
"log"
"net"
Expand All @@ -12,47 +13,48 @@ import (
"regexp"
"strings"
"sync"
"syscall"
"unicode"
)

var haProxyCmd = "haproxy"

var cmdRunHa = func(args []string) error {
var stdoutBuf, stderrBuf bytes.Buffer
cmd := exec.Command(haProxyCmd, args...)

stdoutIn, _ := cmd.StdoutPipe()
stderrIn, _ := cmd.StderrPipe()

stdout := io.MultiWriter(os.Stdout, &stdoutBuf)
stderr := io.MultiWriter(os.Stderr, &stderrBuf)
cmd.Start()

go func() {
io.Copy(stdout, stdoutIn)
}()

go func() {
io.Copy(stderr, stderrIn)
}()

err := cmd.Wait()

outStr, errStr := string(stdoutBuf.Bytes()), string(stderrBuf.Bytes())
combinedOut := fmt.Sprintf("\nstdout:\n%s\nstderr:\n%s\n", outStr, errStr)

if exitError, ok := err.(*exec.ExitError); ok {
waitStatus := exitError.Sys().(syscall.WaitStatus)
fmt.Printf("Exit Status: %s\n", []byte(fmt.Sprintf("%d", waitStatus.ExitStatus())))
return fmt.Errorf(combinedOut)
}
if errStr != "" {
fmt.Println("The configuration file is valid, but there still may be a misconfiguration",
"somewhere that will give unexpected results, please verify:", combinedOut)
}
return nil
var stdoutBuf, stderrBuf bytes.Buffer
cmd := exec.Command(haProxyCmd, args...)

stdoutIn, _ := cmd.StdoutPipe()
stderrIn, _ := cmd.StderrPipe()

stdout := io.MultiWriter(os.Stdout, &stdoutBuf)
stderr := io.MultiWriter(os.Stderr, &stderrBuf)
cmd.Start()

go func() {
io.Copy(stdout, stdoutIn)
}()

go func() {
io.Copy(stderr, stderrIn)
}()

err := cmd.Wait()

outStr, errStr := string(stdoutBuf.Bytes()), string(stderrBuf.Bytes())
combinedOut := fmt.Sprintf("\nstdout:\n%s\nstderr:\n%s\n", outStr, errStr)

if exitError, ok := err.(*exec.ExitError); ok {
waitStatus := exitError.Sys().(syscall.WaitStatus)
fmt.Printf("Exit Status: %s\n", []byte(fmt.Sprintf("%d", waitStatus.ExitStatus())))
return fmt.Errorf(combinedOut)
}

if errStr != "" {
fmt.Println("The configuration file is valid, but there still may be a misconfiguration",
"somewhere that will give unexpected results, please verify:", combinedOut)
}

return nil
}

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

0 comments on commit 951a0a1

Please sign in to comment.