Add initial prototype (#1)

* Add survey library to select server

* Add speedtest

* Add --random flag to connect

* Add list command

* Cache server list

* Tail the openvpn logs so that it appears in vpngate logs

* Add goreleaser action

* Add golangci-lint action
This commit is contained in:
Dave Gallant
2020-12-31 02:56:01 -05:00
committed by GitHub
parent c52d1e990a
commit a2afbc1e35
17 changed files with 1355 additions and 0 deletions

43
pkg/exec/run.go Normal file
View File

@@ -0,0 +1,43 @@
package exec
import (
"bytes"
"os"
"os/exec"
"strings"
"github.com/juju/errors"
"github.com/rs/zerolog/log"
)
// Run executes anycommand in workDir and returns stdout and error.
func Run(path string, workDir string, args ...string) (string, error) {
_, err := exec.LookPath(path)
if err != nil {
log.Error().Msgf("%s is required, please install it", path)
os.Exit(1)
}
cmd := exec.Command(path, args...)
cmd.Dir = workDir
stdout := &bytes.Buffer{}
stderr := &bytes.Buffer{}
cmd.Stdout = stdout
cmd.Stderr = stderr
log.Debug().Msgf("Executing " + strings.Join(cmd.Args, " "))
err = cmd.Run()
output := strings.TrimSpace(stdout.String())
errOut := strings.TrimSpace(stderr.String())
if output != "" {
log.Debug().Msgf(output)
}
if errOut != "" {
log.Debug().Msgf(errOut)
}
if _, ok := err.(*exec.ExitError); !ok {
return output, errors.Trace(err)
}
if err != nil {
return output, errors.Annotatef(err, path, cmd.Args, errOut)
}
return output, nil
}