Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
C
Coredns
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
Railgun
Coredns
Commits
430f11a6
Commit
430f11a6
authored
Mar 24, 2016
by
Miek Gieben
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add context.WithTimeout
Closes #41
parent
4fe39f9e
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
10 additions
and
6 deletions
+10
-6
middleware/etcd/etcd.go
middleware/etcd/etcd.go
+9
-5
middleware/etcd/setup_test.go
middleware/etcd/setup_test.go
+1
-1
No files found.
middleware/etcd/etcd.go
View file @
430f11a6
...
@@ -4,6 +4,7 @@ package etcd
...
@@ -4,6 +4,7 @@ package etcd
import
(
import
(
"encoding/json"
"encoding/json"
"strings"
"strings"
"time"
"github.com/miekg/coredns/middleware"
"github.com/miekg/coredns/middleware"
"github.com/miekg/coredns/middleware/etcd/msg"
"github.com/miekg/coredns/middleware/etcd/msg"
...
@@ -47,7 +48,9 @@ func (g Etcd) Records(name string, exact bool) ([]msg.Service, error) {
...
@@ -47,7 +48,9 @@ func (g Etcd) Records(name string, exact bool) ([]msg.Service, error) {
// Get is a wrapper for client.Get that uses SingleInflight to suppress multiple outstanding queries.
// Get is a wrapper for client.Get that uses SingleInflight to suppress multiple outstanding queries.
func
(
g
Etcd
)
Get
(
path
string
,
recursive
bool
)
(
*
etcdc
.
Response
,
error
)
{
func
(
g
Etcd
)
Get
(
path
string
,
recursive
bool
)
(
*
etcdc
.
Response
,
error
)
{
resp
,
err
:=
g
.
Inflight
.
Do
(
path
,
func
()
(
interface
{},
error
)
{
resp
,
err
:=
g
.
Inflight
.
Do
(
path
,
func
()
(
interface
{},
error
)
{
r
,
e
:=
g
.
Client
.
Get
(
g
.
Ctx
,
path
,
&
etcdc
.
GetOptions
{
Sort
:
false
,
Recursive
:
recursive
})
ctx
,
cancel
:=
context
.
WithTimeout
(
g
.
Ctx
,
etcdTimeout
)
defer
cancel
()
r
,
e
:=
g
.
Client
.
Get
(
ctx
,
path
,
&
etcdc
.
GetOptions
{
Sort
:
false
,
Recursive
:
recursive
})
if
e
!=
nil
{
if
e
!=
nil
{
return
nil
,
e
return
nil
,
e
}
}
...
@@ -145,8 +148,9 @@ func isEtcdNameError(err error) bool {
...
@@ -145,8 +148,9 @@ func isEtcdNameError(err error) bool {
}
}
const
(
const
(
priority
=
10
// default priority when nothing is set
priority
=
10
// default priority when nothing is set
ttl
=
300
// default ttl when nothing is set
ttl
=
300
// default ttl when nothing is set
minTtl
=
60
minTtl
=
60
hostmaster
=
"hostmaster"
hostmaster
=
"hostmaster"
etcdTimeout
=
5
*
time
.
Second
)
)
middleware/etcd/setup_test.go
View file @
430f11a6
...
@@ -37,7 +37,7 @@ const (
...
@@ -37,7 +37,7 @@ const (
)
)
func
init
()
{
func
init
()
{
ctx
=
context
.
TODO
(
)
ctx
,
_
=
context
.
WithTimeout
(
ctx
.
Background
(),
etcdTimeout
)
etcdCfg
:=
etcdc
.
Config
{
etcdCfg
:=
etcdc
.
Config
{
Endpoints
:
[]
string
{
"http://localhost:2379"
},
Endpoints
:
[]
string
{
"http://localhost:2379"
},
...
...
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