api/plugins/tls_interceptor/addr_utils.go
Peter Kurfer ca1ac7d89a
Move plugins to top level directory in repository
- update Makefiles and GoReleaser config
- update dependencies
2020-04-11 15:31:08 +02:00

20 lines
424 B
Go

package main
import (
"fmt"
"regexp"
"strings"
)
var (
ipExtractionRegex = regexp.MustCompile(`(.+):\d{1,5}$`)
)
func extractIPFromAddress(addr string) (string, error) {
matches := ipExtractionRegex.FindAllStringSubmatch(addr, -1)
if len(matches) > 0 && len(matches[0]) >= 1 {
return strings.Trim(matches[0][1], "[]"), nil
} else {
return "", fmt.Errorf("failed to extract IP address from addr %s", addr)
}
}