-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfd-consul-sd.go
73 lines (65 loc) · 1.41 KB
/
confd-consul-sd.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
// Copyright (c) 2014 John Engelman. All rights reserved.
// Use of this source code is governed by the Apache License, Version 2.0
// that can be found in the LICENSE file.
package main
import (
"bufio"
"flag"
"fmt"
"net"
"os"
// "github.com/kelseyhightower/confd/backends"
"github.com/johnrengelman/confd-consul-sd/consul"
"github.com/kelseyhightower/confd/log"
)
var (
client *consul.Client
)
func main() {
flag.Parse()
if printVersion {
fmt.Printf("confd-consul-sd %s\n", Version)
os.Exit(0)
}
config = Config{
Transport: "tcp",
Port: 6000,
Socket: "/var/run/confd-consul-sd.sock",
}
processFlags()
// Configure logging.
log.SetQuiet(config.Quiet)
log.SetVerbose(config.Verbose)
log.SetDebug(config.Debug)
log.Notice("Starting confd-consul-sd")
ln, err := net.Listen("tcp", ":6000")
if err != nil {
log.Error("Could not listen on port 6000")
os.Exit(1)
}
defer ln.Close()
for {
conn, err := ln.Accept()
if err != nil {
continue
}
go HandleRequest(conn)
}
}
func HandleRequest(conn net.Conn) {
log.Info("Handling request")
reader := bufio.NewReader(conn)
writer := bufio.NewWriter(conn)
prefix, err := reader.ReadString('\n')
if err != nil {
log.Error("Error handling request")
return
}
log.Info("Retrieving keys for prefix: " + prefix)
keys := RetrieveKeys(prefix)
writer.WriteString(keys)
conn.Close()
}
func RetrieveKeys(prefix string) string {
return "{}"
}