-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy paththings-gui.go
More file actions
109 lines (88 loc) · 2.38 KB
/
things-gui.go
File metadata and controls
109 lines (88 loc) · 2.38 KB
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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
package main
import (
"flag"
"fmt"
"os"
"os/signal"
socketio "github.com/doquangtan/socketio/v4"
"github.com/joho/godotenv"
)
// AppVersion exposes version information
const AppVersion = "1.3.5"
var cookieName = "uid"
var cookieMaxAge = 6048000 // (seconds) 10 weeks
var (
// env variables
thingsguiAddress string
thingsguiAuthMethod string
thingsguiSsl bool
thingsguiAic bool
thingsguiTokenApi string
useLocalSession bool
useCookieSession bool
// flag variables
disableOpenBrowser bool
envPath string
serverHost string
serverPort uint16
timeout uint16
)
func parseFlags() {
var p uint
var t uint
flag.StringVar(&serverHost, "host", "localhost", "Specific host for the http webserver.")
flag.StringVar(&envPath, "env", ".env", "Path of .env file.")
flag.UintVar(&p, "port", 5000, "Specific port for the http webserver.")
flag.UintVar(&t, "timeout", 0, "Connect and query timeout in seconds")
flag.BoolVar(&disableOpenBrowser, "disable-open-browser", false, "opens ThingsGUI in your default browser")
flag.Parse()
serverPort = uint16(p)
timeout = uint16(t)
}
func readEnvVariables() {
err := godotenv.Load(envPath)
if err != nil {
fmt.Println(err)
}
thingsguiAddress = os.Getenv("THINGSGUI_ADDRESS")
thingsguiAuthMethod = os.Getenv("THINGSGUI_AUTH_METHOD")
thingsguiTokenApi = os.Getenv("THINGSGUI_TOKEN_API")
if isTrue(os.Getenv("THINGSGUI_SSL")) {
thingsguiSsl = true
if isTrue(os.Getenv("THINGSGUI_AIC")) {
thingsguiAic = true
}
}
if isTrue(os.Getenv("THINGSGUI_USE_COOKIE_SESSION")) {
useCookieSession = true
}
if isTrue(os.Getenv("THINGSGUI_USE_LOCAL_SESSION")) {
useLocalSession = true
}
if isTrue(os.Getenv("USE_COOKIE_SESSION")) {
fmt.Println("Environmental variable \"USE_COOKIE_SESSION\" is obsolete and renamed to \"THINGSGUI_USE_COOKIE_SESSION\"")
}
if isTrue(os.Getenv("USE_LOCAL_SESSION")) {
fmt.Println("Environmental variable \"USE_LOCAL_SESSION\" is obsolete and renamed to \"THINGSGUI_USE_LOCAL_SESSION\"")
}
}
func main() {
app := app{}
app.clients = make(map[string]*client)
parseFlags()
readEnvVariables()
newSessions()
app.server = socketio.New()
// on interrup clean up
c := make(chan os.Signal, 1)
signal.Notify(c, os.Interrupt)
go func() {
for sig := range c {
if sig == os.Interrupt {
app.quit()
os.Exit(1)
}
}
}()
app.start()
}