Add logging to all handlers

This commit is contained in:
Marc Di Luzio 2020-06-06 16:26:44 +01:00
parent ca00a64112
commit 3a36f8f84f

View file

@ -89,6 +89,7 @@ func HandleRegister(s *Server, vars map[string]string, b io.ReadCloser, w io.Wri
} else {
// Save out the new accounts
fmt.Printf("New account registered\tname:%s\tid:%s", acc.Name, acc.Id)
response.Id = acc.Id.String()
response.Success = true
@ -117,10 +118,12 @@ func HandleSpawn(s *Server, vars map[string]string, b io.ReadCloser, w io.Writer
} else if id, err := uuid.Parse(id); err != nil {
response.Error = "Provided account ID was invalid"
} else if pos, _, err := s.SpawnRoverForAccount(id); err != nil {
} else if pos, rover, err := s.SpawnRoverForAccount(id); err != nil {
response.Error = err.Error()
} else {
fmt.Printf("New rover spawned\taccount:%s\trover:%s\tpos:%+v", id, rover, pos)
response.Success = true
response.Position = pos
}
@ -155,6 +158,7 @@ func HandleCommand(s *Server, vars map[string]string, b io.ReadCloser, w io.Writ
response.Error = fmt.Sprintf("Failed to execute commands: %s", err)
} else {
fmt.Printf("Queued commands\taccount:%s\tcommands:%+v", id, data.Commands)
response.Success = true
}
@ -181,6 +185,7 @@ func HandleRadar(s *Server, vars map[string]string, b io.ReadCloser, w io.Writer
response.Error = fmt.Sprintf("Error getting radar from rover: %s", err)
} else {
fmt.Printf("Responded with radar\taccount:%s\tradar:%+v", id, radar)
response.Rovers = radar.Rovers
response.Success = true
}
@ -208,6 +213,7 @@ func HandleRover(s *Server, vars map[string]string, b io.ReadCloser, w io.Writer
response.Error = fmt.Sprintf("Error getting radar from rover: %s", err)
} else {
fmt.Printf("Responded with rover\taccount:%s\trover:%+v", id, pos)
response.Position = pos
response.Success = true
}