make PlanetInfos json serializable for ogamed
for
package ogame
+import "encoding/json"
+
// SystemInfos planets information for a specific system
type SystemInfos struct {
galaxy int
@@ -25,6 +27,19 @@ func (s *SystemInfos) Position(idx int) *PlanetInfos {
return s.planets[idx-1]
}
+// MarshalJSON export private fields to json for ogamed
+func (s SystemInfos) MarshalJSON() ([]byte, error) {
+ var tmp struct {
+ Galaxy int
+ System int
+ Planets [15]*PlanetInfos
+ }
+ tmp.Galaxy = s.galaxy
+ tmp.System = s.system
+ tmp.Planets = s.planets
+ return json.Marshal(tmp)
+}
+
// MoonInfos public information of a moon in the galaxy page
type MoonInfos struct {
ID int
