This repository has been archived by the owner on Mar 19, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
main.go
65 lines (62 loc) · 1.88 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
package main
import (
"fmt"
"log"
"net/http"
"os"
"os/exec"
"runtime"
"strconv"
"time"
filehandle "Robot_Monitor_Web/backend/FileHandle"
serialhandle "Robot_Monitor_Web/backend/SerialHandle"
webhandle "Robot_Monitor_Web/backend/WebHandle"
)
func main() {
fmt.Println(` ____ __ __ __
/\ _ \ /\ \ /\ \__ / \_/ \ __/\ \__
\ \ \_\ \ ___\ \ \____ ___\ \ _\ /\ \ ___ ___ /\_\ \ _\ ___ _ __
\ \ / / __ \ \ __ \ / __ \ \ \/ \ \ \__\ \ / __ \ / _ \/\ \ \ \/ / __ \/\ __\
\ \ \\ \ /\ \_\ \ \ \_\ \/\ \_\ \ \ \_ \ \ \_/\ \/\ \_\ \/\ \/\ \ \ \ \ \_/\ \_\ \ \ \/
\ \_\ \_\ \____/\ \____/\ \____/\ \__\ \ \_\\ \_\ \____/\ \_\ \_\ \_\ \__\ \____/\ \_\
\/_/\/ /\/___/ \/___/ \/___/ \/__/ \/_/ \/_/\/___/ \/_/\/_/\/_/\/__/\/___/ \/_/ `)
filehandle.LoadSaves()
defer serialhandle.CloseSerialPort()
go func() {
for {
time.Sleep(5 * time.Second)
filehandle.SaveAll()
}
}()
http.Handle("/", http.FileServer(http.Dir("./frontend/dist/")))
webhandle.Reg()
port := ""
if len(os.Args) > 1 {
p, _ := strconv.Atoi(os.Args[1])
if p > 0 && p < 65535 {
port = ":" + os.Args[1]
} else {
port = ":8080"
}
} else {
port = ":8080"
}
log.Println("Listen on " + port)
log.Println("Don't close this before you have done")
var commands = map[string]string{
"windows": "explorer.exe",
"darwin": "open",
"linux": "xdg-open",
}
run, ok := commands[runtime.GOOS]
if !ok {
log.Printf("don't know how to open things on %s platform", runtime.GOOS)
} else {
go func() {
log.Println("Your browser will start in 3 seconds")
time.Sleep(3 * time.Second)
exec.Command(run, "http://localhost"+port).Start()
}()
}
log.Fatal(http.ListenAndServe(port, nil))
}