-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
47 lines (39 loc) · 1.11 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
package main
import (
"fmt"
"log"
"net/rpc"
"os"
"github.com/wamphlett/ledblinky-proxy/config"
"github.com/wamphlett/ledblinky-proxy/pkg/intercepting"
"github.com/wamphlett/ledblinky-proxy/pkg/proxying"
)
func main() {
port := 8812
client, err := rpc.DialHTTP("tcp", fmt.Sprintf("localhost:%d", port))
if err == nil {
var reply string
log.Print("handing off to existing proxy service")
err = client.Call("InboundHandler.Handle", os.Args[1:], &reply)
if err != nil {
log.Fatal("inbound handler error:", err)
}
log.Print("arguments passed to proxy\nexiting")
return
}
log.Printf("starting new proxy service on port %d", port)
cfg, err := config.NewFromFile()
if err != nil {
log.Fatalf("failed to load config: %s", err.Error())
}
interceptor := intercepting.New()
proxy := proxying.New(interceptor, cfg.LEDBlinkyPath, int64(port))
proxy.ConfigurePublishers(cfg.Receivers)
// make sure the first set of args are handled
proxy.Handle(os.Args[1:])
// start the proxy and listen for further arguments
if err := proxy.Start(); err != nil {
log.Print("failed to start proxy service")
return
}
}