-
Notifications
You must be signed in to change notification settings - Fork 4
/
main.go
88 lines (72 loc) · 2.14 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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
package main
import (
"fmt"
"log"
"os"
"path/filepath"
"github.com/RackHD/inservice/uuid"
"github.com/spf13/viper"
)
func keys(m map[string]interface{}) []string {
keys := []string{}
for key := range m {
keys = append(keys, key)
}
return keys
}
var binaryName, buildDate, buildUser, commitHash, goVersion, osArch, releaseVersion string
func main() {
log.Println(binaryName)
log.Println(" Release version: " + releaseVersion)
log.Println(" Built On: " + buildDate)
log.Println(" Build By: " + buildUser)
log.Println(" Commit Hash: " + commitHash)
log.Println(" Go version: " + goVersion)
log.Println(" OS/Arch: " + osArch)
dir, err := filepath.Abs(filepath.Dir(os.Args[0]))
if err != nil {
log.Fatalf("InService Agent Configuration Error: %s\n", err)
}
viper.SetConfigName("inservice")
viper.SetConfigType("json")
viper.AddConfigPath("/etc/inservice.d")
viper.AddConfigPath(dir)
viper.AddConfigPath("$GOPATH/bin")
viper.AddConfigPath("$HOME")
err = viper.ReadInConfig()
if err != nil {
log.Fatalf("InService Agent Configuration Error: %s\n", err)
}
log.Printf("InService Agent Configuration: %s\n", viper.ConfigFileUsed())
// Host configuration end point for SSDP location advertisement.
http := HTTPServer{
Address: viper.GetString("agent.http.address"),
Port: viper.GetInt("agent.http.port"),
ConfigFile: viper.ConfigFileUsed(),
URI: viper.GetString("agent.http.uri"),
}
go http.Serve()
// Host SSDP Server for advertising Agent/Plugin capabilities.
ssdp := SSDPServer{
ServiceType: viper.GetString("agent.ssdp.serviceType"),
DeviceUUID: uuid.GetUUID(viper.GetString("agent.ssdp.cacheFile")),
Location: fmt.Sprintf(
"http://%s:%d/%s",
viper.GetString("agent.http.address"),
viper.GetInt("agent.http.port"),
viper.GetString("agent.http.uri"),
),
MaxAge: viper.GetInt("agent.ssdp.maxAge"),
}
go ssdp.Serve()
// Host Plugins
plugins, err := NewPluginServer(
viper.GetString("agent.grpc.address"),
viper.GetInt("agent.grpc.port"),
keys(viper.GetStringMap("plugins")),
)
if err != nil {
log.Fatalf("InService Agent Plugin Server Error: %s\n", err)
}
plugins.Serve()
}