-
Notifications
You must be signed in to change notification settings - Fork 13
/
trackingstatus.go
56 lines (50 loc) · 1.29 KB
/
trackingstatus.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
// SPDX-License-Identifier: ISC
// Copyright (c) 2014-2020 Bitmark Inc.
// Use of this source code is governed by an ISC
// license that can be found in the LICENSE file.
package reservoir
// TrackingStatus - result of track payment/try proof
type TrackingStatus int
// possible status values
const (
TrackingNotFound TrackingStatus = iota
TrackingAccepted TrackingStatus = iota
TrackingProcessed TrackingStatus = iota
TrackingInvalid TrackingStatus = iota
)
// String - convert the tracking value for printf
func (ts TrackingStatus) String() string {
switch ts {
case TrackingNotFound:
return "NotFound"
case TrackingAccepted:
return "Accepted"
case TrackingProcessed:
return "Processed"
case TrackingInvalid:
return "Invalid"
default:
return "*Unknown*"
}
}
// MarshalText - convert the tracking value for JSON
func (ts TrackingStatus) MarshalText() ([]byte, error) {
buffer := []byte(ts.String())
return buffer, nil
}
// UnmarshalText - convert the tracking value from JSON to enumeration
func (ts *TrackingStatus) UnmarshalText(s []byte) error {
switch string(s) {
case "NotFound":
*ts = TrackingNotFound
case "Accepted":
*ts = TrackingAccepted
case "Processed":
*ts = TrackingProcessed
case "Invalid":
*ts = TrackingInvalid
default:
*ts = TrackingInvalid
}
return nil
}