-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
71 lines (55 loc) · 1.37 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
package main
import (
"os"
"os/signal"
"embed"
"net"
"strconv"
)
// import internal packages
import (
"D3VL/WebWrap/packages/logging"
"D3VL/WebWrap/packages/open-browser"
"D3VL/WebWrap/packages/server"
)
//go:embed static
var embeddedFS embed.FS
func findAvailablePort() (int, error) {
address, err := net.ResolveTCPAddr("tcp", "localhost:0")
if err != nil {
return 0, err
}
listener, err := net.ListenTCP("tcp", address)
if err != nil {
return 0, err
}
defer listener.Close()
return listener.Addr().(*net.TCPAddr).Port, nil
}
func main() {
// listen for interrupt signal
interrupt := make(chan os.Signal, 1)
signal.Notify(interrupt, os.Interrupt)
log.EnableVerbose()
log.Debug("WebWrap Initializing...")
log.Info("Starting...")
// generate a random port number
portInt, err := findAvailablePort()
if err != nil {
log.Error("Error finding an available port: " + err.Error())
return
}
port := strconv.Itoa(portInt)
go func() {
server.Start(embeddedFS, port);
}()
browser.Open("http://127.0.0.1:" + port)
log.Info("When you are done, close this window to exit")
for {
select {
case <-interrupt:
log.Debug("Process interrupted")
return
}
}
}