forked from BuxOrg/bux
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmodel_transaction_status.go
52 lines (42 loc) · 1.2 KB
/
model_transaction_status.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
package bux
import (
"database/sql/driver"
"fmt"
)
// DraftStatus draft transaction status
type DraftStatus string
const (
// DraftStatusDraft is when the transaction is a draft
DraftStatusDraft DraftStatus = statusDraft
// DraftStatusCanceled is when the draft is canceled
DraftStatusCanceled DraftStatus = statusCanceled
// DraftStatusExpired is when the draft has expired
DraftStatusExpired DraftStatus = statusExpired
// DraftStatusComplete is when the draft transaction is complete
DraftStatusComplete DraftStatus = statusComplete
)
// Scan will scan the value into Struct, implements sql.Scanner interface
func (t *DraftStatus) Scan(value interface{}) error {
xType := fmt.Sprintf("%T", value)
var stringValue string
if xType == ValueTypeString {
stringValue = value.(string)
} else {
stringValue = string(value.([]byte))
}
switch stringValue {
case statusDraft:
*t = DraftStatusDraft
case statusCanceled:
*t = DraftStatusCanceled
case statusExpired:
*t = DraftStatusExpired
case statusComplete:
*t = DraftStatusComplete
}
return nil
}
// Value return json value, implement driver.Valuer interface
func (t DraftStatus) Value() (driver.Value, error) {
return string(t), nil
}