-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
67 lines (52 loc) · 1.33 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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
package main
import (
"flag"
"log"
"os"
"os/signal"
"time"
"github.com/BurntSushi/toml"
"github.com/oleksandr/bonjour"
)
var (
serviceServers []*bonjour.Server
servicesConfig = flag.String("services", "services.toml", "The config file defining services to proxy")
)
type service struct {
Name string
ServiceType string
Domain string
Port int
Host string
IP string
TextData []string
}
type config struct {
ProxyService []service
}
func main() {
flag.Parse()
var services config
if _, err := toml.DecodeFile(*servicesConfig, &services); err != nil {
log.Fatal(err)
}
for _, serviceServer := range services.ProxyService {
log.Printf("Starting Bonjour Proxy for %+v", serviceServer)
s, err := bonjour.RegisterProxy(serviceServer.Name, serviceServer.ServiceType, serviceServer.Domain, serviceServer.Port, serviceServer.Host, serviceServer.IP, serviceServer.TextData, nil)
if err != nil {
log.Fatal(err)
}
log.Printf("Started Bonjour Proxy for %s", serviceServer.Name)
serviceServers = append(serviceServers, s)
}
c := make(chan os.Signal, 1)
signal.Notify(c, os.Interrupt, os.Kill)
for range c {
for _, serviceServer := range serviceServers {
serviceServer.Shutdown()
}
time.Sleep(1 * time.Second)
log.Println("Stopped all Bonjour Proxies")
os.Exit(0)
}
}