Skip to content

Commit

Permalink
generate: Don't serialize Spec.Linux as an empty JSON object
Browse files Browse the repository at this point in the history
The "does the marshaled JSON look like '{}'?" check is a pretty cheap
trick, but it was the easiest way I could think of for "is there
anything useful in here?".

Signed-off-by: W. Trevor King <wking@tremily.us>
  • Loading branch information
wking committed Sep 24, 2016
1 parent 96609ba commit 7fcc366
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions generate/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,16 @@ func (g *Generator) Spec() *rspec.Spec {

// Save writes the spec into w.
func (g *Generator) Save(w io.Writer) error {
if g.spec.Linux != nil {
buf, err := json.Marshal(g.spec.Linux)
if err != nil {
return err
}
if string(buf) == "{}" {
g.spec.Linux = nil
}
}

data, err := json.MarshalIndent(g.spec, "", "\t")
if err != nil {
return err
Expand Down

0 comments on commit 7fcc366

Please sign in to comment.