-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.go
44 lines (42 loc) · 1.18 KB
/
server.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
package main
import (
"encoding/json"
"fmt"
"io"
"net/http"
"os"
)
func HandleGSI(port string) error {
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
var activity DotaGsiRequest
bytes, err := io.ReadAll(r.Body)
if err != nil {
ShowToast("Server Error: Error reading request body", err.Error())
fmt.Println("Error reading body", err.Error())
return
}
err = json.Unmarshal(bytes, &activity)
if err != nil {
ShowToast("Server Error: Error decoding JSON", err.Error())
fmt.Println("ERROR", err.Error())
return
}
// fmt.Println("GSI Received, JSON:", string(bytes))
fmt.Println("[Server] Request received")
if checkbox.Checked() {
Update(activity)
} else {
fmt.Println("Skipping update (disabled)")
}
})
go func() {
err := http.ListenAndServe(":"+port, nil)
if err != nil {
ShowMessageBox("Error", fmt.Sprintf("Error starting HTTP server!\nPort: %s\nError: %s\n\nClick \"Ok\" to close the application", port, err.Error()), MessageBoxTypeOk)
os.Exit(1)
return
}
}()
ShowToast("Started, waiting for Dota2", "You can close or disable application in system tray")
return nil
}