forked from fishworks/gofish
-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
install_receipt.go
38 lines (33 loc) · 980 Bytes
/
install_receipt.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
package receipt
import (
"encoding/json"
"io"
"time"
)
const ReceiptFilename = "INSTALL_RECEIPT.json"
type InstallReceipt struct {
// The name of the food installed
Name string `json:"name"`
// Which rig did this food come from?
Rig string `json:"rig"`
// Time that this food was last modified (upgraded)
LastModified time.Time `json:"last-modified"`
// What version of GoFish was this last modified with?
GoFishVersion string `json:"gofish-version"`
}
// NewFromReader reads in an install receipt from an io.Reader. Useful when reading from a file stream.
func NewFromReader(r io.Reader) (*InstallReceipt, error) {
var receipt InstallReceipt
err := json.NewDecoder(r).Decode(&receipt)
return &receipt, err
}
// Save writes the install receipt into the given io.Writer.
func (i *InstallReceipt) Save(w io.Writer) error {
data, err := json.MarshalIndent(i, "", " ")
if err != nil {
return err
}
_, err = w.Write(data)
w.Write([]byte("\n"))
return err
}