-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathpreferences.go
66 lines (51 loc) · 1.26 KB
/
preferences.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
61
62
63
64
65
66
package preferences
import (
"time"
"github.com/pkg/errors"
"golang.org/x/text/language"
"github.com/code-payments/code-server/pkg/code/data/user"
)
var (
defaultLocale = language.English
)
type Record struct {
Id uint64
DataContainerId user.DataContainerID
Locale language.Tag
LastUpdatedAt time.Time
}
func (r *Record) Validate() error {
if err := r.DataContainerId.Validate(); err != nil {
return errors.Wrap(err, "invalid data container id")
}
if r.Locale.String() == language.Und.String() {
return errors.New("locale is undefined")
}
return nil
}
func (r *Record) Clone() Record {
return Record{
Id: r.Id,
DataContainerId: r.DataContainerId,
Locale: r.Locale,
LastUpdatedAt: r.LastUpdatedAt,
}
}
func (r *Record) CopyTo(dst *Record) {
dst.Id = r.Id
dst.DataContainerId = r.DataContainerId
dst.Locale = r.Locale
dst.LastUpdatedAt = r.LastUpdatedAt
}
// GetDefaultPreferences returns the default set of user preferences
func GetDefaultPreferences(id *user.DataContainerID) *Record {
return &Record{
DataContainerId: *id,
Locale: defaultLocale,
LastUpdatedAt: time.Now(),
}
}
// GetDefaultLocale returns the default locale setting
func GetDefaultLocale() language.Tag {
return defaultLocale
}