From adfcd11f9d9fa316d7982e6ec065cb7259060bec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miguel=20=C3=81ngel=20Ortu=C3=B1o?= Date: Sun, 27 Mar 2022 09:55:16 +0200 Subject: [PATCH] v0.59.0 release (#219) --- CHANGELOG.md | 2 +- pkg/util/net/net.go | 42 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 43 insertions(+), 1 deletion(-) create mode 100644 pkg/util/net/net.go diff --git a/CHANGELOG.md b/CHANGELOG.md index 7f0058e36..8deaa499d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,7 +4,7 @@ ## 0.59.0 (2022/03/26) -* [FEATURE] Improve k8s compatibility. [#219](https://github.com/ortuman/jackal/pull/219), [#220](https://github.com/ortuman/jackal/pull/220), +* [FEATURE] Improve k8s compatibility. [#219](https://github.com/ortuman/jackal/pull/219), [#220](https://github.com/ortuman/jackal/pull/220), ## 0.58.0 (2022/03/04) diff --git a/pkg/util/net/net.go b/pkg/util/net/net.go new file mode 100644 index 000000000..e6851dc26 --- /dev/null +++ b/pkg/util/net/net.go @@ -0,0 +1,42 @@ +// Copyright 2022 The jackal Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package net + +import ( + "fmt" + "net" + "strconv" + "strings" +) + +// SRVResolve performs SRV resolution over dns. +func SRVResolve(service, proto, remoteAddr string) ([]string, error) { + var retVal []string + + _, addrs, err := net.LookupSRV(service, proto, remoteAddr) + if err != nil { + return nil, err + } + for _, addr := range addrs { + if addr.Target == "." { + continue + } + host := strings.TrimSuffix(addr.Target, ".") + port := strconv.Itoa(int(addr.Port)) + + retVal = append(retVal, fmt.Sprintf("%s:%s", host, port)) + } + return retVal, nil +}