-
Notifications
You must be signed in to change notification settings - Fork 402
/
payment.go
46 lines (39 loc) · 1.14 KB
/
payment.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
39
40
41
42
43
44
45
46
// Copyright (C) 2020 Storj Labs, Inc.
// See LICENSE for copying information.
package compensation
import (
"io"
"os"
"storj.io/common/strictcsv"
"storj.io/storj/private/currency"
)
// Payment represents an actual payment that happened.
type Payment struct {
Period Period `csv:"period"`
NodeID NodeID `csv:"node-id"`
Amount currency.MicroUnit `csv:"amount"`
Receipt *string `csv:"receipt"`
Notes *string `csv:"notes"`
}
// LoadPayments loads a collection of Payments from a file on disk containing
// them in CSV form.
func LoadPayments(path string) ([]Payment, error) {
f, err := os.Open(path)
if err != nil {
return nil, Error.Wrap(err)
}
defer func() { _ = f.Close() }()
return ReadPayments(f)
}
// ReadPayments reads a collection of Payments in CSV form.
func ReadPayments(r io.Reader) ([]Payment, error) {
var payments []Payment
if err := strictcsv.Read(r, &payments); err != nil {
return nil, err
}
return payments, nil
}
// WritePayments writes a collection of payments in CSV form.
func WritePayments(w io.Writer, payments []Payment) error {
return strictcsv.Write(w, payments)
}