frostfs-sdk-go/ns/dns.go
Pavel Karpy f7172adf18 [#170] oid, cid: Refactor and document package functionality
Signed-off-by: Pavel Karpy <carpawell@nspcc.ru>
2022-04-13 17:32:25 +03:00

35 lines
673 B
Go

package ns
import (
"net"
cid "github.com/nspcc-dev/neofs-sdk-go/container/id"
)
// DNS looks up NeoFS names using system DNS.
//
// See also net package.
type DNS struct{}
// ResolveContainerName looks up for DNS TXT records for the given domain name
// and returns the first one which represents valid container ID in a string format.
// Otherwise, returns an error.
//
// See also net.LookupTXT.
func (x *DNS) ResolveContainerName(name string) (id cid.ID, err error) {
records, err := net.LookupTXT(name)
if err != nil {
return
}
for i := range records {
err = id.DecodeString(records[i])
if err == nil {
return
}
}
err = errNotFound
return
}