summaryrefslogtreecommitdiff
path: root/internal/wireguard
diff options
context:
space:
mode:
authorjwijenbergh <jeroenwijenbergh@protonmail.com>2022-06-20 15:20:18 +0200
committerjwijenbergh <jeroenwijenbergh@protonmail.com>2022-06-20 15:20:18 +0200
commit2252135fadb8c579ad27345e3203be755130e3cd (patch)
treeed5a530e85b43736fc0bc28c927cfa8488f9199b /internal/wireguard
parent7af07c596166bf93b79a9d0816b1950dde360fb9 (diff)
Refactor: Errors to have one custom type that is to be wrapped
- For this an `internal/types` package is created with a custom error type - This custom error type can give back the cause and traceback of an error
Diffstat (limited to 'internal/wireguard')
-rw-r--r--internal/wireguard/wireguard.go12
1 files changed, 3 insertions, 9 deletions
diff --git a/internal/wireguard/wireguard.go b/internal/wireguard/wireguard.go
index db20067..bb26b69 100644
--- a/internal/wireguard/wireguard.go
+++ b/internal/wireguard/wireguard.go
@@ -3,6 +3,8 @@ package wireguard
import (
"fmt"
"regexp"
+
+ "github.com/jwijenbergh/eduvpn-common/internal/types"
"golang.zx2c4.com/wireguard/wgctrl/wgtypes"
)
@@ -10,7 +12,7 @@ func GenerateKey() (wgtypes.Key, error) {
key, keyErr := wgtypes.GeneratePrivateKey()
if keyErr != nil {
- return key, &WireguardGenerateKeyError{Err: keyErr}
+ return key, &types.WrappedErrorMessage{Message: "failed generating WireGuard key", Err: keyErr}
}
return key, nil
}
@@ -28,11 +30,3 @@ func ConfigAddKey(config string, key wgtypes.Key) string {
to_replace := fmt.Sprintf("%s\nPrivateKey = %s", interface_section, key.String())
return interface_re.ReplaceAllString(config, to_replace)
}
-
-type WireguardGenerateKeyError struct {
- Err error
-}
-
-func (e *WireguardGenerateKeyError) Error() string {
- return fmt.Sprintf("failed generating Wireguard key with error: %v", e.Err)
-}