-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaccount.go
57 lines (51 loc) · 2.18 KB
/
account.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 account
import (
"context"
)
// SignupRequest is a user's intention to sign up.
// It is not necessarily a signup request will be granted. For instance, if a username is already claimed,
// a duplicate user won't be created.
type SignupRequest struct {
// ID is a request ID generated by a user to help with requests deduplications.
ID string `json:"request_id"`
// Username is a name user chose on sign up.
Username string `json:"username"`
// Partition is a number of a partition where the signup request was stored.
Partition int32 `json:"-"`
// SequenceID is ID assigned internally. For example, in Kafka it is an offset of the message.
SequenceID int64 `json:"-"`
}
// SignupResponse represents a server answer to a SignupRequest.
type SignupResponse struct {
// RequestID is a request ID generated by a user to help with requests deduplication.
RequestID string `json:"request_id"`
// Username is a name user chose on sign up.
Username string `json:"username"`
// Success indicates whether a signup request was successful.
Success bool `json:"success"`
// Partition is a number of a partition where the signup response was stored.
Partition int32 `json:"-"`
// SequenceID is ID assigned internally. For example, in Kafka it is an offset of the message.
SequenceID int64 `json:"-"`
}
// User represents a signed up user.
type User struct {
// ID of a user assigned internally by a service, e.g., UUID.
ID string
Username string
}
// UserService represents a service to store user accounts.
type UserService interface {
CreateUser(ctx context.Context, u *User) error
ByUsername(ctx context.Context, username string) (*User, error)
}
// SignupService represents a service where a user can sign up by creating a request.
// The result is provided by Responses.
type SignupService interface {
CreateRequest(ctx context.Context, req *SignupRequest) error
// Requests calls f to process signup requests as they arrive.
Requests(ctx context.Context, f func(req *SignupRequest)) error
CreateResponse(ctx context.Context, resp *SignupResponse) error
// Responses calls f to process signup responses as they arrive.
Responses(ctx context.Context, f func(req *SignupResponse)) error
}