wireguard: rename EndpointAddress.Name to Host
and add String() method Signed-off-by: Alejandro Mery <amery@jpi.io>
This commit is contained in:
+16
-2
@@ -3,6 +3,7 @@ package wireguard
|
|||||||
import (
|
import (
|
||||||
"encoding/base64"
|
"encoding/base64"
|
||||||
"errors"
|
"errors"
|
||||||
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"net/netip"
|
"net/netip"
|
||||||
"strconv"
|
"strconv"
|
||||||
@@ -44,10 +45,23 @@ type PeerConfig struct {
|
|||||||
|
|
||||||
// EndpointAddress is a host:port pair to reach the Peer
|
// EndpointAddress is a host:port pair to reach the Peer
|
||||||
type EndpointAddress struct {
|
type EndpointAddress struct {
|
||||||
Name string
|
Host string
|
||||||
Port uint16
|
Port uint16
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (ep EndpointAddress) String() string {
|
||||||
|
switch {
|
||||||
|
case ep.Host == "":
|
||||||
|
return ""
|
||||||
|
case ep.Port == 0:
|
||||||
|
return ep.Host
|
||||||
|
case !strings.ContainsRune(ep.Host, ':'):
|
||||||
|
return fmt.Sprintf("%s:%v", ep.Host, ep.Port)
|
||||||
|
default:
|
||||||
|
return fmt.Sprintf("[%s]:%v", ep.Host, ep.Port)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// FromString sets the EndpointAddress from a given "[host]:port"
|
// FromString sets the EndpointAddress from a given "[host]:port"
|
||||||
func (ep *EndpointAddress) FromString(s string) error {
|
func (ep *EndpointAddress) FromString(s string) error {
|
||||||
host, port, err := core.SplitHostPort(s)
|
host, port, err := core.SplitHostPort(s)
|
||||||
@@ -55,7 +69,7 @@ func (ep *EndpointAddress) FromString(s string) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
ep.Name = host
|
ep.Host = host
|
||||||
|
|
||||||
switch {
|
switch {
|
||||||
case port != "":
|
case port != "":
|
||||||
|
|||||||
Reference in New Issue
Block a user