logs-analyzer/signoz/pkg/query-service/utils/port.go

22 lines
331 B
Go
Raw Normal View History

2024-09-02 22:47:30 +03:00
package utils
import (
"net"
"strconv"
)
// GetPort returns the port of an endpoint address.
func GetPort(addr net.Addr) (int, error) {
_, port, err := net.SplitHostPort(addr.String())
if err != nil {
return -1, err
}
parsedPort, err := strconv.Atoi(port)
if err != nil {
return -1, err
}
return parsedPort, nil
}