-
Notifications
You must be signed in to change notification settings - Fork 0
/
record.go
36 lines (30 loc) · 893 Bytes
/
record.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
package record
import (
"time"
"github.com/denistakeda/mpass/proto"
)
type Record interface {
GetId() string
GetLastUpdateDate() time.Time
ToProto() *proto.Record
ProvideToClient(printer printer) error
}
type printer interface {
Printf(format string, a ...any)
}
func FromProto(rec *proto.Record) Record {
lastUpdateDate := rec.LastUpdateDate.AsTime()
switch i := rec.Record.(type) {
case *proto.Record_LoginPasswordRecord:
return loginPasswordRecordFromProto(rec.Id, lastUpdateDate, i.LoginPasswordRecord)
case *proto.Record_TextRecord:
return textRecordFromProto(rec.Id, lastUpdateDate, i.TextRecord)
case *proto.Record_BinaryRecord:
return binaryRecordFromProto(rec.Id, lastUpdateDate, i.BinaryRecord)
case *proto.Record_BankCardRecord:
return bankCardRecordFromProto(rec.Id, lastUpdateDate, i.BankCardRecord)
default:
// Should never happen
return nil
}
}