chore(config): rename Reader to Source struct
This commit is contained in:
@@ -9,14 +9,14 @@ import (
|
||||
"github.com/qdm12/govalid/port"
|
||||
)
|
||||
|
||||
func (r *Reader) readWireguardSelection() (
|
||||
func (s *Source) readWireguardSelection() (
|
||||
selection settings.WireguardSelection, err error) {
|
||||
selection.EndpointIP, err = r.readWireguardEndpointIP()
|
||||
selection.EndpointIP, err = s.readWireguardEndpointIP()
|
||||
if err != nil {
|
||||
return selection, err
|
||||
}
|
||||
|
||||
selection.EndpointPort, err = r.readWireguardCustomPort()
|
||||
selection.EndpointPort, err = s.readWireguardCustomPort()
|
||||
if err != nil {
|
||||
return selection, err
|
||||
}
|
||||
@@ -28,29 +28,29 @@ func (r *Reader) readWireguardSelection() (
|
||||
|
||||
var ErrIPAddressParse = errors.New("cannot parse IP address")
|
||||
|
||||
func (r *Reader) readWireguardEndpointIP() (endpointIP net.IP, err error) {
|
||||
key, s := r.getEnvWithRetro("VPN_ENDPOINT_IP", "WIREGUARD_ENDPOINT_IP")
|
||||
if s == "" {
|
||||
func (s *Source) readWireguardEndpointIP() (endpointIP net.IP, err error) {
|
||||
key, value := s.getEnvWithRetro("VPN_ENDPOINT_IP", "WIREGUARD_ENDPOINT_IP")
|
||||
if value == "" {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
endpointIP = net.ParseIP(s)
|
||||
endpointIP = net.ParseIP(value)
|
||||
if endpointIP == nil {
|
||||
return nil, fmt.Errorf("environment variable %s: %w: %s",
|
||||
key, ErrIPAddressParse, s)
|
||||
key, ErrIPAddressParse, value)
|
||||
}
|
||||
|
||||
return endpointIP, nil
|
||||
}
|
||||
|
||||
func (r *Reader) readWireguardCustomPort() (customPort *uint16, err error) {
|
||||
key, s := r.getEnvWithRetro("VPN_ENDPOINT_PORT", "WIREGUARD_ENDPOINT_PORT")
|
||||
if s == "" {
|
||||
func (s *Source) readWireguardCustomPort() (customPort *uint16, err error) {
|
||||
key, value := s.getEnvWithRetro("VPN_ENDPOINT_PORT", "WIREGUARD_ENDPOINT_PORT")
|
||||
if value == "" {
|
||||
return nil, nil //nolint:nilnil
|
||||
}
|
||||
|
||||
customPort = new(uint16)
|
||||
*customPort, err = port.Validate(s)
|
||||
*customPort, err = port.Validate(value)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("environment variable %s: %w", key, err)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user