Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
10
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
mf
go-multiaddr-dns
Commits
807a4262
Commit
807a4262
authored
Apr 07, 2021
by
vyzo
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
more nuanced handling of custom resolvers
parent
f9a06197
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
20 additions
and
13 deletions
+20
-13
resolve.go
resolve.go
+20
-13
No files found.
resolve.go
View file @
807a4262
...
...
@@ -20,11 +20,12 @@ type BasicResolver interface {
}
// Resolver is an object capable of resolving dns multiaddrs by using one or more BasicResolvers;
// it supports custom per TLD resolvers.
// It also implements the BasicResolver interface so that it can act as a custom per TLD resolver.
// it supports custom per domain/TLD resolvers.
// It also implements the BasicResolver interface so that it can act as a custom per domain/TLD
// resolver.
type
Resolver
struct
{
def
BasicResolver
tld
map
[
string
]
BasicResolver
def
BasicResolver
custom
map
[
string
]
BasicResolver
}
var
_
BasicResolver
=
(
*
Resolver
)(
nil
)
...
...
@@ -54,23 +55,29 @@ func WithDefaultResolver(def BasicResolver) Option {
}
}
// WithTLDResolver specifies a custom resolver for a TLD.
func
With
TLD
Resolver
(
tld
string
,
rslv
BasicResolver
)
Option
{
// WithTLDResolver specifies a custom resolver for a
domain/
TLD.
func
With
Domain
Resolver
(
domain
string
,
rslv
BasicResolver
)
Option
{
return
func
(
r
*
Resolver
)
error
{
r
.
tld
[
tld
]
=
rslv
r
.
custom
[
domain
]
=
rslv
return
nil
}
}
func
(
r
*
Resolver
)
getResolver
(
domain
string
)
BasicResolver
{
parts
:=
strings
.
Split
(
domain
,
"."
)
tld
:=
parts
[
len
(
parts
)
-
1
]
rslv
,
ok
:=
r
.
custom
[
domain
]
if
ok
{
return
rslv
}
rslv
,
ok
:=
r
.
tld
[
tld
]
if
!
ok
{
rslv
=
r
.
def
for
i
:=
strings
.
Index
(
domain
,
"."
);
i
!=
-
1
;
i
=
strings
.
Index
(
domain
,
","
)
{
domain
=
domain
[
i
+
1
:
]
rslv
,
ok
=
r
.
custom
[
domain
]
if
ok
{
return
rslv
}
}
return
rslv
return
r
.
def
}
// Resolve resolves a DNS multiaddr.
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment