Skip to content

Commit

Permalink
add speed to server
Browse files Browse the repository at this point in the history
  • Loading branch information
MahdiAw committed Apr 12, 2023
1 parent 820039a commit b695cd9
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
1 change: 1 addition & 0 deletions dispatcher/camp.go
Expand Up @@ -11,6 +11,7 @@ type Soldier struct {
Name string `json:"name"`
Ip string `json:"ip"`
LastRequest time.Time `json:"last_request"`
Speed int `json:"speed"`
}

const (
Expand Down
9 changes: 9 additions & 0 deletions dispatcher/server.go
Expand Up @@ -6,6 +6,7 @@ import (
"net"
"net/http"
"os"
"strconv"
"time"
)

Expand Down Expand Up @@ -37,6 +38,14 @@ func HandleCamp(writer http.ResponseWriter, request *http.Request, d *Dispatcher
if soldier.Name != "" {
soldier.LastRequest = time.Now()
}
speed := request.URL.Query().Get("speed")
if speed != "" {
soldier.Speed, err = strconv.Atoi(speed)
if err != nil {
http.Error(writer, "error getting speed", http.StatusBadRequest)
return
}
}
}
if request.Method == "POST" {
//add soldier to camp
Expand Down

0 comments on commit b695cd9

Please sign in to comment.