Compare commits

..

2 Commits

Author SHA1 Message Date
amery 79d1783401 jpictl: initial env command [WIP]
Signed-off-by: Alejandro Mery <amery@jpi.io>
2023-08-22 01:35:53 +00:00
amery bf2e2a50c7 zones: WriteEnv() [WIP]
Signed-off-by: Alejandro Mery <amery@jpi.io>
2023-08-22 01:35:53 +00:00
+2 -22
View File
@@ -3,7 +3,6 @@ package wireguard
import ( import (
"encoding/base64" "encoding/base64"
"errors" "errors"
"fmt"
"io" "io"
"net/netip" "net/netip"
"strconv" "strconv"
@@ -45,29 +44,10 @@ 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 {
Host string Name string
Port uint16 Port uint16
} }
// Name returns the first part of a hostname
func (ep EndpointAddress) Name() string {
before, _, _ := strings.Cut(ep.Host, ".")
return before
}
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)
@@ -75,7 +55,7 @@ func (ep *EndpointAddress) FromString(s string) error {
return err return err
} }
ep.Host = host ep.Name = host
switch { switch {
case port != "": case port != "":