-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
45 lines (34 loc) · 898 Bytes
/
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
package main
import (
"encoding/json"
"flag"
"fmt"
"os"
"github.com/HiDeoo/KeyPrompter/cli"
"github.com/HiDeoo/KeyPrompter/keyboard"
"github.com/HiDeoo/KeyPrompter/net"
)
var Version = "development version"
func main() {
config := flag.String("c", "", "Optional client configuration file")
port := flag.Int("p", 8484, "Port used to run the web UI")
version := flag.Bool("v", false, "Print the current KeyPrompter version")
flag.Parse()
if *version {
fmt.Printf("KeyPrompter %s\n", Version)
os.Exit(0)
}
var clientConfig *cli.ClientConfig
if len(*config) > 0 {
clientConfig = cli.ReadConfig(*config)
} else {
clientConfig = new(cli.ClientConfig)
}
pool := net.Serve(*port, clientConfig)
keyboard.HandleEvents(func(keyboardEvent keyboard.KeyboardEvent) {
eventJson, err := json.Marshal(keyboardEvent)
if err == nil {
pool.Broadcast <- eventJson
}
})
}