-
Notifications
You must be signed in to change notification settings - Fork 2
/
main.go
53 lines (46 loc) · 1.05 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
52
53
package main
import (
"code.google.com/p/gcfg"
"log"
"net"
)
type config struct {
Pgreplicaproxy struct {
Listen []string
Backend []string
}
}
var masterRequestChannel = make(chan serverRequest)
var replicaRequestChannel = make(chan serverRequest)
var serverStatusUpdateChannel = make(chan serverStatusUpdate)
var exitChan = make(chan bool)
func main() {
cfg := config{}
err := gcfg.ReadFileInto(&cfg, "pgreplicaproxy.cfg")
if err != nil {
log.Fatal(err)
}
go serverStatusOracle()
go manageBackendKeyDataStorage()
for _, backend := range cfg.Pgreplicaproxy.Backend {
go monitorBackend(backend)
}
for _, listen := range cfg.Pgreplicaproxy.Listen {
go listenFrontend(listen)
}
// Don't finish main()
<-exitChan
}
func listenFrontend(listen string) {
ln, err := net.Listen("tcp", listen)
if err != nil {
log.Fatal(err)
}
for {
conn, err := ln.Accept()
if err != nil {
log.Fatal(err)
}
go handleIncomingConnection(conn, masterRequestChannel, replicaRequestChannel)
}
}