-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathstore.go
57 lines (46 loc) · 999 Bytes
/
store.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
57
package rendezvous
import (
"context"
"errors"
"time"
)
var (
ErrNotFound = errors.New("rendezvous record not found")
)
type Record struct {
Id uint64
Key string
Location string
CreatedAt time.Time
LastUpdatedAt time.Time
}
type Store interface {
Save(ctx context.Context, record *Record) error
Get(ctx context.Context, key string) (*Record, error)
Delete(ctx context.Context, key string) error
}
func (r *Record) Validate() error {
if len(r.Key) == 0 {
return errors.New("key is required")
}
if len(r.Location) == 0 {
return errors.New("location is required")
}
return nil
}
func (r *Record) Clone() Record {
return Record{
Id: r.Id,
Key: r.Key,
Location: r.Location,
CreatedAt: r.CreatedAt,
LastUpdatedAt: r.LastUpdatedAt,
}
}
func (r *Record) CopyTo(dst *Record) {
dst.Id = r.Id
dst.Key = r.Key
dst.Location = r.Location
dst.CreatedAt = r.CreatedAt
dst.LastUpdatedAt = r.LastUpdatedAt
}