From 48037ba90f0c9b06abe5c13a5063dc0fc3456bd9 Mon Sep 17 00:00:00 2001 From: Alain Gilbert Date: Wed, 17 Aug 2022 02:22:05 -0700 Subject: [PATCH] cleanup, use switch instead of if-else --- extracts_v6.go | 51 +++++++++++++++++++++++++------------------------- 1 file changed, 26 insertions(+), 25 deletions(-) diff --git a/extracts_v6.go b/extracts_v6.go index 27a69a1f..92ee3032 100644 --- a/extracts_v6.go +++ b/extracts_v6.go @@ -210,32 +210,33 @@ func extractMoonFromDocV6(doc *goquery.Document, b *OGame, v any) (Moon, error) } func extractCelestialFromDocV6(doc *goquery.Document, b *OGame, v any) (Celestial, error) { - if planetID, ok := v.(PlanetID); ok { - return extractPlanetByIDFromDocV6(doc, b, planetID) - } else if moonID, ok := v.(MoonID); ok { - return extractMoonByIDFromDocV6(doc, b, moonID) - } else if celestialID, ok := v.(CelestialID); ok { - return extractCelestialByIDFromDocV6(doc, b, celestialID) - } else if id, ok := v.(int); ok { - return extractCelestialByIDFromDocV6(doc, b, CelestialID(id)) - } else if id, ok := v.(int32); ok { - return extractCelestialByIDFromDocV6(doc, b, CelestialID(id)) - } else if id, ok := v.(int64); ok { - return extractCelestialByIDFromDocV6(doc, b, CelestialID(id)) - } else if id, ok := v.(float32); ok { - return extractCelestialByIDFromDocV6(doc, b, CelestialID(id)) - } else if id, ok := v.(float64); ok { - return extractCelestialByIDFromDocV6(doc, b, CelestialID(id)) - } else if id, ok := v.(lua.LNumber); ok { - return extractCelestialByIDFromDocV6(doc, b, CelestialID(id)) - } else if coord, ok := v.(Coordinate); ok { - if coord.Type == PlanetType { - return extractPlanetByCoordFromDocV6(doc, b, coord) - } else if coord.Type == MoonType { - return extractMoonByCoordFromDocV6(doc, b, coord) + switch vv := v.(type) { + case PlanetID: + return extractPlanetByIDFromDocV6(doc, b, vv) + case MoonID: + return extractMoonByIDFromDocV6(doc, b, vv) + case CelestialID: + return extractCelestialByIDFromDocV6(doc, b, vv) + case int: + return extractCelestialByIDFromDocV6(doc, b, CelestialID(vv)) + case int32: + return extractCelestialByIDFromDocV6(doc, b, CelestialID(vv)) + case int64: + return extractCelestialByIDFromDocV6(doc, b, CelestialID(vv)) + case float32: + return extractCelestialByIDFromDocV6(doc, b, CelestialID(vv)) + case float64: + return extractCelestialByIDFromDocV6(doc, b, CelestialID(vv)) + case lua.LNumber: + return extractCelestialByIDFromDocV6(doc, b, CelestialID(vv)) + case Coordinate: + if vv.Type == PlanetType { + return extractPlanetByCoordFromDocV6(doc, b, vv) + } else if vv.Type == MoonType { + return extractMoonByCoordFromDocV6(doc, b, vv) } - } else if coordStr, ok := v.(string); ok { - coord, err := ParseCoord(coordStr) + case string: + coord, err := ParseCoord(vv) if err != nil { return nil, err }