package main import ( "embed" "io/fs" "log" "net/http" "os" "os/signal" "syscall" "imuslab.com/remdeskvm/remdeskd/mod/remdeshid" ) const development = true var ( remdesHIDController *remdeshid.Controller ) /* Web Server Static Files */ //go:embed www var embeddedFiles embed.FS var webfs http.FileSystem func init() { // Initiate the web server static files if development { webfs = http.Dir("./www") } else { // Embed the ./www folder and trim the prefix subFS, err := fs.Sub(embeddedFiles, "www") if err != nil { log.Fatal(err) } webfs = http.FS(subFS) } // Initiate the HID controller remdesHIDController = remdeshid.NewHIDController(&remdeshid.Config{ PortName: "COM4", BaudRate: 115200, }) } func main() { //Start the HID controller err := remdesHIDController.Connect() if err != nil { log.Fatal(err) } // Handle program exit to close the HID controller c := make(chan os.Signal, 1) signal.Notify(c, os.Interrupt, syscall.SIGTERM) go func() { <-c log.Println("Shutting down...") remdesHIDController.Close() os.Exit(0) }() // Start the web server http.HandleFunc("/hid", remdesHIDController.HIDWebSocketHandler) http.Handle("/", http.FileServer(webfs)) addr := ":8080" log.Printf("Serving on http://localhost%s\n", addr) log.Fatal(http.ListenAndServe(addr, nil)) }