-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
72 lines (60 loc) · 1.67 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
package main
import (
"fmt"
"os"
"strings"
log "github.com/sirupsen/logrus"
"github.com/spf13/cobra"
"github.com/getblank/blank-router/internet"
"github.com/getblank/blank-router/intranet"
"github.com/getblank/blank-router/settings"
"github.com/getblank/blank-router/sr"
)
var (
buildTime string
gitHash string
version = "0.2.6"
)
func main() {
if os.Getenv("BLANK_DEBUG") != "" {
log.SetLevel(log.DebugLevel)
}
if os.Getenv("DEV_MODE") != "" {
settings.DevMode = true
}
log.SetFormatter(&log.JSONFormatter{})
var srAddress *string
var verFlag *bool
rootCmd := &cobra.Command{
Use: "router",
Short: "Router for Blank platform",
Long: "This is the router subsystem for Blank platform.",
Run: func(cmd *cobra.Command, args []string) {
if *verFlag {
printVersion()
return
}
if sr := os.Getenv("BLANK_SERVICE_REGISTRY_URI"); len(sr) > 0 {
srAddress = &sr
}
if srPort := os.Getenv("BLANK_SERVICE_REGISTRY_PORT"); len(srPort) > 0 {
addr := "ws://localhost:" + srPort
srAddress = &addr
}
log.Info("Router started")
settings.SRAddress = *srAddress
settings.SRHTTPAddress = "http:" + strings.TrimPrefix(*srAddress, "ws:")
go internet.Init(sr.SR(), version)
intranet.Init(true)
},
}
srAddress = rootCmd.PersistentFlags().StringP("service-registry", "s", "ws://localhost:1234", "Service registry uri")
verFlag = rootCmd.PersistentFlags().BoolP("version", "v", false, "Prints version and exit")
if err := rootCmd.Execute(); err != nil {
println(err.Error())
os.Exit(-1)
}
}
func printVersion() {
fmt.Printf("blank-router: \tv%s \t build time: %s \t commit hash: %s \n", version, buildTime, gitHash)
}