-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathstore.go
60 lines (47 loc) · 1.22 KB
/
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
58
59
60
package identity
import (
"context"
"errors"
"time"
"github.com/code-payments/code-server/pkg/code/data/user"
)
var (
// ErrNotFound is returned when a user being fetched does not exist.
ErrNotFound = errors.New("user not found")
// ErrAlreadyExists is returned when a new user record is being added already
// exists.
ErrAlreadyExists = errors.New("user already exists")
)
// User is the highest order of a form of identity.
type Record struct {
ID *user.UserID
View *user.View
IsStaffUser bool
IsBanned bool
CreatedAt time.Time
}
// Store manages a user's identity.
type Store interface {
// Put creates a new user.
Put(ctx context.Context, record *Record) error
// GetByID fetches a user by its ID.
GetByID(ctx context.Context, id *user.UserID) (*Record, error)
// GetByView fetches a user by a view.
GetByView(ctx context.Context, view *user.View) (*Record, error)
}
// Validate validates a Record
func (r *Record) Validate() error {
if r == nil {
return errors.New("record is nil")
}
if err := r.ID.Validate(); err != nil {
return err
}
if err := r.View.Validate(); err != nil {
return err
}
if r.CreatedAt.IsZero() {
return errors.New("creation time is zero")
}
return nil
}