-
Notifications
You must be signed in to change notification settings - Fork 394
/
paystub.go
56 lines (50 loc) · 1.89 KB
/
paystub.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
47
48
49
50
51
52
53
54
55
56
// 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"
)
// Paystub contains the basic information about a payment that is to be made.
type Paystub struct {
Period Period `csv:"period"`
NodeID NodeID `csv:"node-id"`
Codes Codes `csv:"codes"`
UsageAtRest float64 `csv:"usage-at-rest"`
UsageGet int64 `csv:"usage-get"`
UsagePut int64 `csv:"usage-put"`
UsageGetRepair int64 `csv:"usage-get-repair"`
UsagePutRepair int64 `csv:"usage-put-repair"`
UsageGetAudit int64 `csv:"usage-get-audit"`
CompAtRest currency.MicroUnit `csv:"comp-at-rest"`
CompGet currency.MicroUnit `csv:"comp-get"`
CompPut currency.MicroUnit `csv:"comp-put"`
CompGetRepair currency.MicroUnit `csv:"comp-get-repair"`
CompPutRepair currency.MicroUnit `csv:"comp-put-repair"`
CompGetAudit currency.MicroUnit `csv:"comp-get-audit"`
SurgePercent int64 `csv:"surge-percent"`
Owed currency.MicroUnit `csv:"owed"`
Held currency.MicroUnit `csv:"held"`
Disposed currency.MicroUnit `csv:"disposed"`
Paid currency.MicroUnit `csv:"paid"`
Distributed currency.MicroUnit `csv:"distributed"`
}
// LoadPaystubs loads a collection of Paystubs in CSV form from the provided file.
func LoadPaystubs(path string) ([]Paystub, error) {
f, err := os.Open(path)
if err != nil {
return nil, Error.Wrap(err)
}
defer func() { _ = f.Close() }()
return ReadPaystubs(f)
}
// ReadPaystubs reads a collection of Paystubs in CSV form.
func ReadPaystubs(r io.Reader) ([]Paystub, error) {
var paystubs []Paystub
if err := strictcsv.Read(r, &paystubs); err != nil {
return nil, err
}
return paystubs, nil
}