Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
G
gost
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Packages
Packages
List
Container Registry
Analytics
Analytics
CI / CD
Code Review
Insights
Issues
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
nanahira
gost
Commits
1e24898e
Commit
1e24898e
authored
Nov 12, 2018
by
ginuerzh
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
resolver now can be compatible with /etc/resolv.conf
parent
d9cce633
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
49 additions
and
31 deletions
+49
-31
resolver.go
resolver.go
+49
-31
No files found.
resolver.go
View file @
1e24898e
...
...
@@ -67,6 +67,7 @@ type resolver struct {
Timeout
time
.
Duration
TTL
time
.
Duration
period
time
.
Duration
domain
string
}
// NewResolver create a new Resolver with the given name servers and resolution timeout.
...
...
@@ -99,6 +100,9 @@ func (r *resolver) Resolve(host string) (ips []net.IP, err error) {
return
[]
net
.
IP
{
ip
},
nil
}
if
!
strings
.
Contains
(
host
,
"."
)
&&
r
.
domain
!=
""
{
host
=
host
+
"."
+
r
.
domain
}
ips
=
r
.
loadCache
(
host
)
if
len
(
ips
)
>
0
{
if
Debug
{
...
...
@@ -198,50 +202,62 @@ func (r *resolver) storeCache(name string, ips []net.IP) {
func
(
r
*
resolver
)
Reload
(
rd
io
.
Reader
)
error
{
var
nss
[]
NameServer
scanner
:=
bufio
.
NewScanner
(
rd
)
for
scanner
.
Scan
()
{
line
:=
scanner
.
Text
()
split
:=
func
(
line
string
)
[]
string
{
if
line
==
""
{
return
nil
}
if
n
:=
strings
.
IndexByte
(
line
,
'#'
);
n
>=
0
{
line
=
line
[
:
n
]
}
line
=
strings
.
Replace
(
line
,
"
\t
"
,
" "
,
-
1
)
line
=
strings
.
TrimSpace
(
line
)
if
line
==
""
{
continue
}
var
ss
[]
string
for
_
,
s
:=
range
strings
.
Split
(
line
,
" "
)
{
if
s
=
strings
.
TrimSpace
(
s
);
s
!=
""
{
ss
=
append
(
ss
,
s
)
}
}
return
ss
}
scanner
:=
bufio
.
NewScanner
(
rd
)
for
scanner
.
Scan
()
{
line
:=
scanner
.
Text
()
ss
:=
split
(
line
)
if
len
(
ss
)
==
0
{
continue
}
if
len
(
ss
)
>=
2
{
// timeout option
if
strings
.
ToLower
(
ss
[
0
])
==
"timeout"
{
switch
ss
[
0
]
{
case
"timeout"
:
// timeout option
if
len
(
ss
)
>
1
{
r
.
Timeout
,
_
=
time
.
ParseDuration
(
ss
[
1
])
continue
}
// ttl option
if
strings
.
ToLower
(
ss
[
0
])
==
"ttl"
{
case
"ttl"
:
// ttl option
if
len
(
ss
)
>
1
{
r
.
TTL
,
_
=
time
.
ParseDuration
(
ss
[
1
])
continue
}
// reload option
if
strings
.
ToLower
(
ss
[
0
])
==
"reload"
{
case
"reload"
:
// reload option
if
len
(
ss
)
>
1
{
r
.
period
,
_
=
time
.
ParseDuration
(
ss
[
1
])
continue
}
case
"domain"
:
if
len
(
ss
)
>
1
{
r
.
domain
=
ss
[
1
]
}
case
"search"
,
"sortlist"
,
"options"
:
// we don't support these features in /etc/resolv.conf
case
"nameserver"
:
// nameserver option, compatible with /etc/resolv.conf
if
len
(
ss
)
<=
1
{
break
}
ss
=
ss
[
1
:
]
fallthrough
default
:
var
ns
NameServer
switch
len
(
ss
)
{
case
0
:
break
case
1
:
ns
.
Addr
=
ss
[
0
]
case
2
:
...
...
@@ -254,6 +270,8 @@ func (r *resolver) Reload(rd io.Reader) error {
}
nss
=
append
(
nss
,
ns
)
}
}
if
err
:=
scanner
.
Err
();
err
!=
nil
{
return
err
}
...
...
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