diff options
-rw-r--r-- | listeners.go | 48 | ||||
-rw-r--r-- | listeners_test.go | 26 | ||||
-rw-r--r-- | modules/caddyhttp/autohttps.go | 2 | ||||
-rw-r--r-- | modules/caddyhttp/reverseproxy/hosts.go | 2 | ||||
-rw-r--r-- | modules/caddyhttp/reverseproxy/selectionpolicies.go | 4 | ||||
-rw-r--r-- | modules/logging/netwriter.go | 2 |
6 files changed, 42 insertions, 42 deletions
diff --git a/listeners.go b/listeners.go index 0bbee8a..e1fd48c 100644 --- a/listeners.go +++ b/listeners.go @@ -254,49 +254,49 @@ type globalListener struct { pc net.PacketConn } -// ParsedAddress contains the individual components +// NetworkAddress contains the individual components // for a parsed network address of the form accepted // by ParseNetworkAddress(). Network should be a // network value accepted by Go's net package. Port // ranges are given by [StartPort, EndPort]. -type ParsedAddress struct { +type NetworkAddress struct { Network string Host string StartPort uint EndPort uint } -// IsUnixNetwork returns true if pa.Network is +// IsUnixNetwork returns true if na.Network is // unix, unixgram, or unixpacket. -func (pa ParsedAddress) IsUnixNetwork() bool { - return isUnixNetwork(pa.Network) +func (na NetworkAddress) IsUnixNetwork() bool { + return isUnixNetwork(na.Network) } // JoinHostPort is like net.JoinHostPort, but where the port // is StartPort + offset. -func (pa ParsedAddress) JoinHostPort(offset uint) string { - if pa.IsUnixNetwork() { - return pa.Host +func (na NetworkAddress) JoinHostPort(offset uint) string { + if na.IsUnixNetwork() { + return na.Host } - return net.JoinHostPort(pa.Host, strconv.Itoa(int(pa.StartPort+offset))) + return net.JoinHostPort(na.Host, strconv.Itoa(int(na.StartPort+offset))) } // PortRangeSize returns how many ports are in // pa's port range. Port ranges are inclusive, // so the size is the difference of start and // end ports plus one. -func (pa ParsedAddress) PortRangeSize() uint { - return (pa.EndPort - pa.StartPort) + 1 +func (na NetworkAddress) PortRangeSize() uint { + return (na.EndPort - na.StartPort) + 1 } // String reconstructs the address string to the form expected // by ParseNetworkAddress(). -func (pa ParsedAddress) String() string { - port := strconv.FormatUint(uint64(pa.StartPort), 10) - if pa.StartPort != pa.EndPort { - port += "-" + strconv.FormatUint(uint64(pa.EndPort), 10) +func (na NetworkAddress) String() string { + port := strconv.FormatUint(uint64(na.StartPort), 10) + if na.StartPort != na.EndPort { + port += "-" + strconv.FormatUint(uint64(na.EndPort), 10) } - return JoinNetworkAddress(pa.Network, pa.Host, port) + return JoinNetworkAddress(na.Network, na.Host, port) } func isUnixNetwork(netw string) bool { @@ -311,17 +311,17 @@ func isUnixNetwork(netw string) bool { // // Network addresses are distinct from URLs and do not // use URL syntax. -func ParseNetworkAddress(addr string) (ParsedAddress, error) { +func ParseNetworkAddress(addr string) (NetworkAddress, error) { var host, port string network, host, port, err := SplitNetworkAddress(addr) if network == "" { network = "tcp" } if err != nil { - return ParsedAddress{}, err + return NetworkAddress{}, err } if isUnixNetwork(network) { - return ParsedAddress{ + return NetworkAddress{ Network: network, Host: host, }, nil @@ -333,19 +333,19 @@ func ParseNetworkAddress(addr string) (ParsedAddress, error) { var start, end uint64 start, err = strconv.ParseUint(ports[0], 10, 16) if err != nil { - return ParsedAddress{}, fmt.Errorf("invalid start port: %v", err) + return NetworkAddress{}, fmt.Errorf("invalid start port: %v", err) } end, err = strconv.ParseUint(ports[1], 10, 16) if err != nil { - return ParsedAddress{}, fmt.Errorf("invalid end port: %v", err) + return NetworkAddress{}, fmt.Errorf("invalid end port: %v", err) } if end < start { - return ParsedAddress{}, fmt.Errorf("end port must not be less than start port") + return NetworkAddress{}, fmt.Errorf("end port must not be less than start port") } if (end - start) > maxPortSpan { - return ParsedAddress{}, fmt.Errorf("port range exceeds %d ports", maxPortSpan) + return NetworkAddress{}, fmt.Errorf("port range exceeds %d ports", maxPortSpan) } - return ParsedAddress{ + return NetworkAddress{ Network: network, Host: host, StartPort: uint(start), diff --git a/listeners_test.go b/listeners_test.go index 25e1394..2828a3b 100644 --- a/listeners_test.go +++ b/listeners_test.go @@ -153,7 +153,7 @@ func TestJoinNetworkAddress(t *testing.T) { func TestParseNetworkAddress(t *testing.T) { for i, tc := range []struct { input string - expectAddr ParsedAddress + expectAddr NetworkAddress expectErr bool }{ { @@ -166,7 +166,7 @@ func TestParseNetworkAddress(t *testing.T) { }, { input: ":1234", - expectAddr: ParsedAddress{ + expectAddr: NetworkAddress{ Network: "tcp", Host: "", StartPort: 1234, @@ -175,7 +175,7 @@ func TestParseNetworkAddress(t *testing.T) { }, { input: "tcp/:1234", - expectAddr: ParsedAddress{ + expectAddr: NetworkAddress{ Network: "tcp", Host: "", StartPort: 1234, @@ -184,7 +184,7 @@ func TestParseNetworkAddress(t *testing.T) { }, { input: "tcp6/:1234", - expectAddr: ParsedAddress{ + expectAddr: NetworkAddress{ Network: "tcp6", Host: "", StartPort: 1234, @@ -193,7 +193,7 @@ func TestParseNetworkAddress(t *testing.T) { }, { input: "tcp4/localhost:1234", - expectAddr: ParsedAddress{ + expectAddr: NetworkAddress{ Network: "tcp4", Host: "localhost", StartPort: 1234, @@ -202,14 +202,14 @@ func TestParseNetworkAddress(t *testing.T) { }, { input: "unix//foo/bar", - expectAddr: ParsedAddress{ + expectAddr: NetworkAddress{ Network: "unix", Host: "/foo/bar", }, }, { input: "localhost:1234-1234", - expectAddr: ParsedAddress{ + expectAddr: NetworkAddress{ Network: "tcp", Host: "localhost", StartPort: 1234, @@ -222,7 +222,7 @@ func TestParseNetworkAddress(t *testing.T) { }, { input: "localhost:0", - expectAddr: ParsedAddress{ + expectAddr: NetworkAddress{ Network: "tcp", Host: "localhost", StartPort: 0, @@ -253,12 +253,12 @@ func TestParseNetworkAddress(t *testing.T) { func TestJoinHostPort(t *testing.T) { for i, tc := range []struct { - pa ParsedAddress + pa NetworkAddress offset uint expect string }{ { - pa: ParsedAddress{ + pa: NetworkAddress{ Network: "tcp", Host: "localhost", StartPort: 1234, @@ -267,7 +267,7 @@ func TestJoinHostPort(t *testing.T) { expect: "localhost:1234", }, { - pa: ParsedAddress{ + pa: NetworkAddress{ Network: "tcp", Host: "localhost", StartPort: 1234, @@ -276,7 +276,7 @@ func TestJoinHostPort(t *testing.T) { expect: "localhost:1234", }, { - pa: ParsedAddress{ + pa: NetworkAddress{ Network: "tcp", Host: "localhost", StartPort: 1234, @@ -286,7 +286,7 @@ func TestJoinHostPort(t *testing.T) { expect: "localhost:1235", }, { - pa: ParsedAddress{ + pa: NetworkAddress{ Network: "unix", Host: "/run/php/php7.3-fpm.sock", }, diff --git a/modules/caddyhttp/autohttps.go b/modules/caddyhttp/autohttps.go index 00853f8..ecb988a 100644 --- a/modules/caddyhttp/autohttps.go +++ b/modules/caddyhttp/autohttps.go @@ -82,7 +82,7 @@ func (app *App) automaticHTTPSPhase1(ctx caddy.Context, repl *caddy.Replacer) er // this maps domain names for automatic HTTP->HTTPS // redirects to their destination server address - redirDomains := make(map[string]caddy.ParsedAddress) + redirDomains := make(map[string]caddy.NetworkAddress) for srvName, srv := range app.Servers { // as a prerequisite, provision route matchers; this is diff --git a/modules/caddyhttp/reverseproxy/hosts.go b/modules/caddyhttp/reverseproxy/hosts.go index 87139c3..23759d1 100644 --- a/modules/caddyhttp/reverseproxy/hosts.go +++ b/modules/caddyhttp/reverseproxy/hosts.go @@ -138,7 +138,7 @@ func (u *Upstream) Full() bool { // field is used. Note that the returned value is not a pointer. func (u *Upstream) fillDialInfo(r *http.Request) (DialInfo, error) { repl := r.Context().Value(caddy.ReplacerCtxKey).(*caddy.Replacer) - var addr caddy.ParsedAddress + var addr caddy.NetworkAddress if u.LookupSRV != "" { // perform DNS lookup for SRV records and choose one diff --git a/modules/caddyhttp/reverseproxy/selectionpolicies.go b/modules/caddyhttp/reverseproxy/selectionpolicies.go index 8a32135..7c36dec 100644 --- a/modules/caddyhttp/reverseproxy/selectionpolicies.go +++ b/modules/caddyhttp/reverseproxy/selectionpolicies.go @@ -370,12 +370,12 @@ func (s HeaderHashSelection) Select(pool UpstreamPool, req *http.Request) *Upstr } // UnmarshalCaddyfile sets up the module from Caddyfile tokens. -func (r *HeaderHashSelection) UnmarshalCaddyfile(d *caddyfile.Dispenser) error { +func (s *HeaderHashSelection) UnmarshalCaddyfile(d *caddyfile.Dispenser) error { for d.Next() { if !d.NextArg() { return d.ArgErr() } - r.Field = d.Val() + s.Field = d.Val() } return nil } diff --git a/modules/logging/netwriter.go b/modules/logging/netwriter.go index 7d2dafa..427bb75 100644 --- a/modules/logging/netwriter.go +++ b/modules/logging/netwriter.go @@ -31,7 +31,7 @@ func init() { type NetWriter struct { Address string `json:"address,omitempty"` - addr caddy.ParsedAddress + addr caddy.NetworkAddress } // CaddyModule returns the Caddy module information. |