Fix all go vet issues

This commit is contained in:
Marc Di Luzio 2020-06-30 23:59:58 +01:00
parent 204c786103
commit b5707ab71c
13 changed files with 195 additions and 170 deletions

View file

@ -9,6 +9,7 @@ import (
"github.com/mdiluz/rove/pkg/version"
)
// Status returns the status of the current server to a gRPC request
func (s *Server) Status(context.Context, *rove.StatusRequest) (*rove.StatusResponse, error) {
response := &rove.StatusResponse{
Ready: true,
@ -26,6 +27,7 @@ func (s *Server) Status(context.Context, *rove.StatusRequest) (*rove.StatusRespo
return response, nil
}
// Register registers a new account for a gRPC request
func (s *Server) Register(ctx context.Context, req *rove.RegisterRequest) (*rove.RegisterResponse, error) {
if len(req.Name) == 0 {
return nil, fmt.Errorf("empty account name")
@ -44,6 +46,7 @@ func (s *Server) Register(ctx context.Context, req *rove.RegisterRequest) (*rove
return &rove.RegisterResponse{}, nil
}
// Rover returns rover information for a gRPC request
func (s *Server) Rover(ctx context.Context, req *rove.RoverRequest) (*rove.RoverResponse, error) {
response := &rove.RoverResponse{}
if len(req.Account) == 0 {
@ -70,6 +73,7 @@ func (s *Server) Rover(ctx context.Context, req *rove.RoverRequest) (*rove.Rover
return response, nil
}
// Radar returns the radar information for a rover
func (s *Server) Radar(ctx context.Context, req *rove.RadarRequest) (*rove.RadarResponse, error) {
if len(req.Account) == 0 {
return nil, fmt.Errorf("empty account name")
@ -95,6 +99,7 @@ func (s *Server) Radar(ctx context.Context, req *rove.RadarRequest) (*rove.Radar
return response, nil
}
// Commands issues commands to the world based on a gRPC request
func (s *Server) Commands(ctx context.Context, req *rove.CommandsRequest) (*rove.CommandsResponse, error) {
if len(req.Account) == 0 {
return nil, fmt.Errorf("empty account")

View file

@ -208,21 +208,22 @@ func (s *Server) LoadWorld() error {
// SpawnRoverForAccount spawns the rover rover for an account
func (s *Server) SpawnRoverForAccount(account string) (string, error) {
if inst, err := s.world.SpawnRover(); err != nil {
inst, err := s.world.SpawnRover()
if err != nil {
return "", err
} else {
err := s.accountant.AssignData(account, "rover", inst)
if err != nil {
log.Printf("Failed to assign rover to account, %s", err)
// Try and clear up the rover
if err := s.world.DestroyRover(inst); err != nil {
log.Printf("Failed to destroy rover after failed rover assign: %s", err)
}
return "", err
} else {
return inst, nil
}
}
err = s.accountant.AssignData(account, "rover", inst)
if err != nil {
log.Printf("Failed to assign rover to account, %s", err)
// Try and clear up the rover
if err := s.world.DestroyRover(inst); err != nil {
log.Printf("Failed to destroy rover after failed rover assign: %s", err)
}
return "", err
}
return inst, nil
}

View file

@ -24,6 +24,7 @@ var data = os.Getenv("DATA_PATH")
// The tick rate of the server in seconds
var tick = os.Getenv("TICK_RATE")
// InnerMain is our main function so tests can run it
func InnerMain() {
// Ensure we've seeded rand
rand.Seed(time.Now().UTC().UnixNano())