18
18
package cores
19
19
20
20
import (
21
+ "encoding/json"
21
22
"strings"
22
23
23
24
paths "github.com/arduino/go-paths-helper"
@@ -41,14 +42,13 @@ type PlatformRelease struct {
41
42
Resource * resources.DownloadResource
42
43
Version * semver.Version
43
44
BoardsManifest []* BoardManifest
44
- Dependencies ToolDependencies // The Dependency entries to load tools.
45
- Platform * Platform `json:"-"`
46
-
47
- Properties * properties.Map `json:"-"`
48
- Boards map [string ]* Board `json:"-"`
49
- Programmers map [string ]* properties.Map `json:"-"`
50
- Menus * properties.Map `json:"-"`
51
- InstallDir * paths.Path `json:"-"`
45
+ Dependencies ToolDependencies // The Dependency entries to load tools.
46
+ Platform * Platform `json:"-"`
47
+ Properties * properties.Map `json:"-"`
48
+ Boards map [string ]* Board `json:"-"`
49
+ Programmers map [string ]* properties.Map `json:"-"`
50
+ Menus * properties.Map `json:"-"`
51
+ InstallDir * paths.Path `json:"-"`
52
52
}
53
53
54
54
// BoardManifest contains information about a board. These metadata are usually
@@ -226,3 +226,25 @@ func (release *PlatformRelease) String() string {
226
226
}
227
227
return release .Platform .String () + "@" + version
228
228
}
229
+
230
+ // MarshalJSON provides a more user friendly serialization for
231
+ // PlatformRelease objects.
232
+ func (release * PlatformRelease ) MarshalJSON () ([]byte , error ) {
233
+ latestStr := ""
234
+ latest := release .Platform .GetLatestRelease ()
235
+ if latest != nil {
236
+ latestStr = latest .Version .String ()
237
+ }
238
+
239
+ return json .Marshal (& struct {
240
+ ID string `json:"ID,omitempty"`
241
+ Installed string `json:"Installed,omitempty"`
242
+ Latest string `json:"Latest,omitempty"`
243
+ Name string `json:"Name,omitempty"`
244
+ }{
245
+ ID : release .Platform .String (),
246
+ Installed : release .Version .String (),
247
+ Latest : latestStr ,
248
+ Name : release .Platform .Name ,
249
+ })
250
+ }
0 commit comments