Apply all golangci-lint fixes
This commit is contained in:
parent
945b3299ac
commit
75910efbe5
8 changed files with 19 additions and 22 deletions
|
@ -47,8 +47,7 @@ func (s *Server) Register(ctx context.Context, req *rove.RegisterRequest) (*rove
|
||||||
}
|
}
|
||||||
|
|
||||||
// Status returns rover information for a gRPC request
|
// Status returns rover information for a gRPC request
|
||||||
func (s *Server) Status(ctx context.Context, req *rove.StatusRequest) (*rove.StatusResponse, error) {
|
func (s *Server) Status(ctx context.Context, req *rove.StatusRequest) (response *rove.StatusResponse, err error) {
|
||||||
response := &rove.StatusResponse{}
|
|
||||||
if len(req.Account) == 0 {
|
if len(req.Account) == 0 {
|
||||||
return nil, fmt.Errorf("empty account name")
|
return nil, fmt.Errorf("empty account name")
|
||||||
|
|
||||||
|
|
|
@ -136,7 +136,9 @@ func (s *Server) Run() {
|
||||||
s.world.ExecuteCommandQueues()
|
s.world.ExecuteCommandQueues()
|
||||||
|
|
||||||
// Save out the new world state
|
// Save out the new world state
|
||||||
s.SaveWorld()
|
if err := s.SaveWorld(); err != nil {
|
||||||
|
log.Fatalf("Failed to save the world: %s", err)
|
||||||
|
}
|
||||||
}); err != nil {
|
}); err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
|
@ -52,7 +52,9 @@ func InnerMain() {
|
||||||
log.Printf("Initialising version %s...\n", version.Version)
|
log.Printf("Initialising version %s...\n", version.Version)
|
||||||
|
|
||||||
// Set the persistence path
|
// Set the persistence path
|
||||||
persistence.SetPath(data)
|
if err := persistence.SetPath(data); err != nil {
|
||||||
|
log.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
// Convert the tick rate
|
// Convert the tick rate
|
||||||
tickRate := 1
|
tickRate := 1
|
||||||
|
|
|
@ -3,10 +3,12 @@ package main
|
||||||
import (
|
import (
|
||||||
"flag"
|
"flag"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
)
|
)
|
||||||
|
|
||||||
func Test_InnerMain_Version(t *testing.T) {
|
func Test_InnerMain_Version(t *testing.T) {
|
||||||
flag.Set("version", "1")
|
assert.NoError(t, flag.Set("version", "1"))
|
||||||
InnerMain()
|
InnerMain()
|
||||||
flag.Set("version", "0")
|
assert.NoError(t, flag.Set("version", "0"))
|
||||||
}
|
}
|
||||||
|
|
|
@ -78,7 +78,9 @@ func LoadConfig() (config Config, err error) {
|
||||||
// Create the path if needed
|
// Create the path if needed
|
||||||
path := filepath.Dir(datapath)
|
path := filepath.Dir(datapath)
|
||||||
if _, err := os.Stat(path); os.IsNotExist(err) {
|
if _, err := os.Stat(path); os.IsNotExist(err) {
|
||||||
os.MkdirAll(path, os.ModePerm)
|
if err := os.MkdirAll(path, os.ModePerm); err != nil {
|
||||||
|
return Config{}, fmt.Errorf("Failed to create data path %s: %s", path, err)
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
// Read the file
|
// Read the file
|
||||||
_, err = os.Stat(datapath)
|
_, err = os.Stat(datapath)
|
||||||
|
|
|
@ -144,19 +144,6 @@ func (a *Atlas) setObject(chunk int, local vector.Vector, object objects.Object)
|
||||||
a.Chunks[chunk] = c
|
a.Chunks[chunk] = c
|
||||||
}
|
}
|
||||||
|
|
||||||
// setTileAndObject sets both tile and object information for location in chunk
|
|
||||||
func (a *Atlas) setTileAndObject(chunk int, local vector.Vector, tile byte, object objects.Object) {
|
|
||||||
c := a.Chunks[chunk]
|
|
||||||
if c.Tiles == nil {
|
|
||||||
c.populate(a.ChunkSize)
|
|
||||||
}
|
|
||||||
|
|
||||||
i := a.chunkTileIndex(local)
|
|
||||||
c.Tiles[i] = tile
|
|
||||||
c.Objects[i] = object
|
|
||||||
a.Chunks[chunk] = c
|
|
||||||
}
|
|
||||||
|
|
||||||
// worldSpaceToChunkLocal gets a chunk local coordinate for a tile
|
// worldSpaceToChunkLocal gets a chunk local coordinate for a tile
|
||||||
func (a *Atlas) worldSpaceToChunkLocal(v vector.Vector) vector.Vector {
|
func (a *Atlas) worldSpaceToChunkLocal(v vector.Vector) vector.Vector {
|
||||||
return vector.Vector{X: maths.Pmod(v.X, a.ChunkSize), Y: maths.Pmod(v.Y, a.ChunkSize)}
|
return vector.Vector{X: maths.Pmod(v.X, a.ChunkSize), Y: maths.Pmod(v.Y, a.ChunkSize)}
|
||||||
|
|
|
@ -60,7 +60,7 @@ func (d Bearing) ShortString() string {
|
||||||
// FromString gets the Direction from a string
|
// FromString gets the Direction from a string
|
||||||
func FromString(s string) (Bearing, error) {
|
func FromString(s string) (Bearing, error) {
|
||||||
for i, d := range bearingStrings {
|
for i, d := range bearingStrings {
|
||||||
if strings.ToLower(d.Long) == strings.ToLower(s) || strings.ToLower(d.Short) == strings.ToLower(s) {
|
if strings.EqualFold(d.Long, s) || strings.EqualFold(d.Short, s) {
|
||||||
return Bearing(i), nil
|
return Bearing(i), nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -91,6 +91,7 @@ func TestWorld_GetSetMovePosition(t *testing.T) {
|
||||||
// Place a tile in front of the rover
|
// Place a tile in front of the rover
|
||||||
world.Atlas.SetObject(vector.Vector{X: 0, Y: 2}, objects.Object{Type: objects.LargeRock})
|
world.Atlas.SetObject(vector.Vector{X: 0, Y: 2}, objects.Object{Type: objects.LargeRock})
|
||||||
newPos, err = world.MoveRover(a, b)
|
newPos, err = world.MoveRover(a, b)
|
||||||
|
assert.NoError(t, err, "Failed to move rover")
|
||||||
assert.Equal(t, pos, newPos, "Failed to correctly not move position for rover into wall")
|
assert.Equal(t, pos, newPos, "Failed to correctly not move position for rover into wall")
|
||||||
|
|
||||||
rover, err = world.GetRover(a)
|
rover, err = world.GetRover(a)
|
||||||
|
@ -168,7 +169,9 @@ func TestWorld_RoverStash(t *testing.T) {
|
||||||
|
|
||||||
// Recharge the rover
|
// Recharge the rover
|
||||||
for i := 0; i < rover.MaximumCharge; i++ {
|
for i := 0; i < rover.MaximumCharge; i++ {
|
||||||
world.RoverRecharge(a)
|
_, err = world.RoverRecharge(a)
|
||||||
|
assert.NoError(t, err)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Place an object
|
// Place an object
|
||||||
|
|
Loading…
Add table
Reference in a new issue