mirror of
https://github.com/aptly-dev/aptly.git
synced 2026-05-06 22:18:28 +00:00
Custom JSON marshalling for PackageDiff, updated test for snapshot diff API. #168
This commit is contained in:
@@ -2,6 +2,8 @@ package deb
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"github.com/AlekSi/pointer"
|
||||
"github.com/ugorji/go/codec"
|
||||
"sort"
|
||||
)
|
||||
@@ -154,6 +156,27 @@ type PackageDiff struct {
|
||||
Left, Right *Package
|
||||
}
|
||||
|
||||
// Check interface
|
||||
var (
|
||||
_ json.Marshaler = PackageDiff{}
|
||||
)
|
||||
|
||||
// MarshalJSON implements json.Marshaler interface
|
||||
func (d PackageDiff) MarshalJSON() ([]byte, error) {
|
||||
serialized := struct {
|
||||
Left, Right *string
|
||||
}{}
|
||||
|
||||
if d.Left != nil {
|
||||
serialized.Left = pointer.ToString(string(d.Left.Key("")))
|
||||
}
|
||||
if d.Right != nil {
|
||||
serialized.Right = pointer.ToString(string(d.Right.Key("")))
|
||||
}
|
||||
|
||||
return json.Marshal(serialized)
|
||||
}
|
||||
|
||||
// PackageDiffs is a list of PackageDiff records
|
||||
type PackageDiffs []PackageDiff
|
||||
|
||||
|
||||
Reference in New Issue
Block a user