forked from skynetservices/skydns
/
main.go
51 lines (42 loc) · 1.08 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
// Copyright (c) 2014 The SkyDNS Authors. All rights reserved.
// Use of this source code is governed by The MIT License (MIT) that can be
// found in the LICENSE file.
package main
import (
"log"
"os"
"strings"
"github.com/coreos/go-etcd/etcd"
)
var (
machines = strings.Split(os.Getenv("ETCD_MACHINES"), ",") // List of URLs to etcd
tlskey = os.Getenv("ETCD_TLSKEY") // TLS private key path
tlspem = os.Getenv("ETCD_TLSPEM") // X509 certificate
)
func newClient() (client *etcd.Client) {
if len(machines) == 1 && machines[0] == "" {
machines[0] = "http://127.0.0.1:4001"
}
if strings.HasPrefix(machines[0], "https://") {
var err error
if client, err = etcd.NewTLSClient(machines, tlspem, tlskey, ""); err != nil {
log.Fatal(err)
}
} else {
client = etcd.NewClient(machines)
}
client.SyncCluster()
return client
}
func main() {
client := newClient()
config, err := LoadConfig(client)
if err != nil {
log.Fatal(err)
}
s := NewServer(config, client)
statsCollect()
if err := s.Run(); err != nil {
log.Fatal(err)
}
}