Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
A
autoradio
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
ale
autoradio
Commits
6c595930
Commit
6c595930
authored
9 years ago
by
ale
Browse files
Options
Downloads
Patches
Plain Diff
pass etcd server URLs as-is to the etcd client
parent
a6bbeb41
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
etcd_client.go
+4
-31
4 additions, 31 deletions
etcd_client.go
with
4 additions
and
31 deletions
etcd_client.go
+
4
−
31
View file @
6c595930
...
...
@@ -4,14 +4,13 @@ import (
"flag"
"io/ioutil"
"log"
"net"
"strings"
"git.autistici.org/ale/autoradio/Godeps/_workspace/src/github.com/coreos/go-etcd/etcd"
)
var
(
etcdMachines
=
flag
.
String
(
"etcd-servers"
,
"
localhost
:2379"
,
"Etcd servers (comma-separated list)"
)
etcdMachines
=
flag
.
String
(
"etcd-servers"
,
"
http://127.0.0.1
:2379"
,
"Etcd server
URL
s (comma-separated list)"
)
etcdCertFile
=
flag
.
String
(
"etcd-cert"
,
""
,
"SSL certificate for etcd client"
)
etcdKeyFile
=
flag
.
String
(
"etcd-key"
,
""
,
"SSL private key for etcd client"
)
etcdCaFile
=
flag
.
String
(
"etcd-ca"
,
""
,
"SSL CA certificate for etcd client"
)
...
...
@@ -25,45 +24,19 @@ func mustLoadFile(path string) string {
return
string
(
data
)
}
// Resolve a list of etcd host:port specs, returning URLs.
func
resolveAll
(
input
[]
string
,
proto
string
)
[]
string
{
var
result
[]
string
for
_
,
hostport
:=
range
input
{
host
,
port
,
err
:=
net
.
SplitHostPort
(
hostport
)
if
err
!=
nil
{
log
.
Fatalf
(
"Error parsing etcd server spec '%s': %s"
,
hostport
,
err
)
}
addrs
,
err
:=
net
.
LookupHost
(
host
)
if
err
!=
nil
{
log
.
Fatalf
(
"Error resolving etcd server spec '%s': %s"
,
hostport
,
err
)
}
for
_
,
a
:=
range
addrs
{
url
:=
proto
+
"://"
+
net
.
JoinHostPort
(
a
,
port
)
result
=
append
(
result
,
url
)
}
}
return
result
}
// NewEtcdClient creates a new etcd client. It uses command-line flags
// to find servers and connection parameters. If the 'strongReads'
// argument is true, read requests will also be sent to the etcd
// master and should be able to see the effect of previous writes.
func
NewEtcdClient
(
strongReads
bool
)
EtcdClient
{
proto
:=
"http"
if
*
etcdCertFile
!=
""
&&
*
etcdKeyFile
!=
""
{
proto
=
"https"
}
// Resolve etcd servers.
machines
:=
resolveAll
(
strings
.
Split
(
*
etcdMachines
,
","
),
proto
)
if
len
(
machines
)
==
0
{
machines
:=
strings
.
Split
(
*
etcdMachines
,
","
)
if
len
(
machines
)
<
1
{
log
.
Fatal
(
"No etcd servers specified!"
)
}
// Create the etcd client.
var
c
*
etcd
.
Client
if
proto
==
"https
"
{
if
*
etcdCertFile
!=
""
&&
*
etcdKeyFile
!=
"
"
{
var
err
error
c
,
err
=
etcd
.
NewTLSClient
(
machines
,
mustLoadFile
(
*
etcdCertFile
),
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment