mirror of
https://github.com/guilhem/headscale-operator.git
synced 2024-11-22 11:32:59 +00:00
36 lines
620 B
Go
36 lines
620 B
Go
package utils
|
|
|
|
import (
|
|
"net"
|
|
"strconv"
|
|
"strings"
|
|
|
|
"google.golang.org/grpc/codes"
|
|
"google.golang.org/grpc/status"
|
|
)
|
|
|
|
func SliptHostPort(hostport string) (string, int, error) {
|
|
host, sListenPort, err := net.SplitHostPort(hostport)
|
|
if err != nil {
|
|
return "", 0, err
|
|
}
|
|
listenPort, err := strconv.Atoi(sListenPort)
|
|
if err != nil {
|
|
return "", 0, err
|
|
}
|
|
return host, listenPort, nil
|
|
}
|
|
|
|
func IgnoreNotFound(err error) error {
|
|
status, ok := status.FromError(err)
|
|
if !ok {
|
|
return err
|
|
}
|
|
|
|
if (status.Code() == codes.NotFound) || strings.Contains(status.Message(), "not found") {
|
|
return nil
|
|
}
|
|
|
|
return err
|
|
}
|