envoyconfig: address strconv.Atoi warnings

Replace Atoi() calls with ParseUint(), and update the buildAddress()
defaultPort parameter to be a uint32. (A uint16 would arguably make more
sense for a port number, but uint32 matches the Envoy proto field.)

Delete a ParseAddress() method that appears to be unused.
This commit is contained in:
Kenneth Jenkins 2024-04-10 11:48:38 -07:00
parent 498c3aa108
commit d4d18c4067
4 changed files with 9 additions and 36 deletions

View file

@ -1,13 +1,5 @@
package envoy
import (
"fmt"
"net"
"strconv"
envoy_config_core_v3 "github.com/envoyproxy/go-control-plane/envoy/config/core/v3"
)
func firstNonEmpty[T interface{ ~string }](args ...T) T {
for _, a := range args {
if a != "" {
@ -16,22 +8,3 @@ func firstNonEmpty[T interface{ ~string }](args ...T) T {
}
return ""
}
// ParseAddress parses a string address into an envoy address.
func ParseAddress(raw string) (*envoy_config_core_v3.Address, error) {
if host, portstr, err := net.SplitHostPort(raw); err == nil {
if port, err := strconv.Atoi(portstr); err == nil {
return &envoy_config_core_v3.Address{
Address: &envoy_config_core_v3.Address_SocketAddress{
SocketAddress: &envoy_config_core_v3.SocketAddress{
Address: host,
PortSpecifier: &envoy_config_core_v3.SocketAddress_PortValue{
PortValue: uint32(port),
},
},
},
}, nil
}
}
return nil, fmt.Errorf("unknown address format: %s", raw)
}