-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathmain.go
More file actions
60 lines (47 loc) · 1.34 KB
/
Copy pathmain.go
File metadata and controls
60 lines (47 loc) · 1.34 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
package main
import (
"embed"
"flag"
"fmt"
"io/fs"
"log"
"net/http"
"os"
"netron/cmdtools"
"netron/handlers"
"github.com/gorilla/mux"
)
//go:embed static/*
var staticFiles embed.FS
func main() {
run := flag.Bool("run", false, "Run the server")
port := flag.String("port", "8080", "Port to run server on")
removeDeps := flag.Bool("remove-deps", false, "Remove installed dependencies")
flag.StringVar(port, "p", "8080", "Port to run server on (shorthand)")
flag.Parse()
if *removeDeps {
cmdtools.RemoveDependency()
os.Exit(0)
}
if !*run {
fmt.Println("Usage:")
fmt.Println(" --run : Run the server (prompts for dependency install if needed)")
fmt.Println(" --remove-deps : Remove dependencies")
fmt.Println(" --port or -p [port]: Specify port (default: 8080)")
os.Exit(1)
}
if !cmdtools.EnsureDependency() {
os.Exit(1)
}
r := mux.NewRouter()
r.HandleFunc("/api/system", handlers.GetSystemInfo).Methods("GET")
r.HandleFunc("/api/speedtest", handlers.GetSpeedTest).Methods("GET")
r.HandleFunc("/api/speedtest/start", handlers.StartSpeedTest).Methods("POST")
staticFS, err := fs.Sub(staticFiles, "static")
if err != nil {
log.Fatal(err)
}
r.PathPrefix("/").Handler(http.FileServer(http.FS(staticFS)))
fmt.Printf("Server starting on :%s\n", *port)
log.Fatal(http.ListenAndServe(":"+*port, r))
}