mirror of
https://github.com/qdm12/gluetun.git
synced 2026-05-06 20:10:11 +02:00
4a78989d9d
- main reason being it's a burden to always define sentinel errors at global scope, wrap them with `%w` instead of using a string directly - only use sentinel errors when it has to be checked using `errors.Is` - replace all usage of these sentinel errors in `fmt.Errorf` with direct strings that were in the sentinel error - exclude the sentinel error definition requirement from .golangci.yml - update unit tests to use ContainersError instead of ErrorIs so it stays as a "not a change detector test" without requiring a sentinel error
32 lines
800 B
Go
32 lines
800 B
Go
package openvpn
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"os/exec"
|
|
"strings"
|
|
)
|
|
|
|
func (c *Configurator) Version25(ctx context.Context) (version string, err error) {
|
|
return c.version(ctx, binOpenvpn25)
|
|
}
|
|
|
|
func (c *Configurator) Version26(ctx context.Context) (version string, err error) {
|
|
return c.version(ctx, binOpenvpn26)
|
|
}
|
|
|
|
func (c *Configurator) version(ctx context.Context, binName string) (version string, err error) {
|
|
cmd := exec.CommandContext(ctx, binName, "--version")
|
|
output, err := c.cmder.Run(cmd)
|
|
if err != nil && err.Error() != "exit status 1" {
|
|
return "", err
|
|
}
|
|
firstLine := strings.Split(output, "\n")[0]
|
|
words := strings.Fields(firstLine)
|
|
const minWords = 2
|
|
if len(words) < minWords {
|
|
return "", fmt.Errorf("version output is too short: %s", firstLine)
|
|
}
|
|
return words[1], nil
|
|
}
|