diff options
author | Michael Muré <batolettre@gmail.com> | 2020-02-08 16:02:49 +0100 |
---|---|---|
committer | Michael Muré <batolettre@gmail.com> | 2020-02-09 02:24:27 +0100 |
commit | d78ed55173935e85673a0b2270d421540baf72fb (patch) | |
tree | ebdd0f5dac88c3013705f02f5097122e292248da /graphql/models/lazy_identity.go | |
parent | 81f5c3e0af9aa4b81662e0781289189703324986 (diff) | |
download | git-bug-d78ed55173935e85673a0b2270d421540baf72fb.tar.gz |
cleanups, doc
Diffstat (limited to 'graphql/models/lazy_identity.go')
-rw-r--r-- | graphql/models/lazy_identity.go | 55 |
1 files changed, 29 insertions, 26 deletions
diff --git a/graphql/models/lazy_identity.go b/graphql/models/lazy_identity.go index 31f4dcc4..bbd36be3 100644 --- a/graphql/models/lazy_identity.go +++ b/graphql/models/lazy_identity.go @@ -11,6 +11,9 @@ import ( "github.com/MichaelMure/git-bug/util/timestamp" ) +// IdentityWrapper is an interface used by the GraphQL resolvers to handle an identity. +// Depending on the situation, an Identity can already be fully loaded in memory or not. +// This interface is used to wrap either a lazyIdentity or a loadedIdentity depending on the situation. type IdentityWrapper interface { Id() entity.Id Name() string @@ -24,9 +27,9 @@ type IdentityWrapper interface { LastModification() (timestamp.Timestamp, error) } -var _ IdentityWrapper = &LazyIdentity{} +var _ IdentityWrapper = &lazyIdentity{} -type LazyIdentity struct { +type lazyIdentity struct { cache *cache.RepoCache excerpt *cache.IdentityExcerpt @@ -34,14 +37,14 @@ type LazyIdentity struct { id *cache.IdentityCache } -func NewLazyIdentity(cache *cache.RepoCache, excerpt *cache.IdentityExcerpt) *LazyIdentity { - return &LazyIdentity{ +func NewLazyIdentity(cache *cache.RepoCache, excerpt *cache.IdentityExcerpt) *lazyIdentity { + return &lazyIdentity{ cache: cache, excerpt: excerpt, } } -func (li *LazyIdentity) load() (*cache.IdentityCache, error) { +func (li *lazyIdentity) load() (*cache.IdentityCache, error) { if li.id != nil { return li.id, nil } @@ -57,15 +60,15 @@ func (li *LazyIdentity) load() (*cache.IdentityCache, error) { return id, nil } -func (li *LazyIdentity) Id() entity.Id { +func (li *lazyIdentity) Id() entity.Id { return li.excerpt.Id } -func (li *LazyIdentity) Name() string { +func (li *lazyIdentity) Name() string { return li.excerpt.Name } -func (li *LazyIdentity) Email() (string, error) { +func (li *lazyIdentity) Email() (string, error) { id, err := li.load() if err != nil { return "", err @@ -73,7 +76,7 @@ func (li *LazyIdentity) Email() (string, error) { return id.Email(), nil } -func (li *LazyIdentity) AvatarUrl() (string, error) { +func (li *lazyIdentity) AvatarUrl() (string, error) { id, err := li.load() if err != nil { return "", err @@ -81,7 +84,7 @@ func (li *LazyIdentity) AvatarUrl() (string, error) { return id.AvatarUrl(), nil } -func (li *LazyIdentity) Keys() ([]*identity.Key, error) { +func (li *lazyIdentity) Keys() ([]*identity.Key, error) { id, err := li.load() if err != nil { return nil, err @@ -89,7 +92,7 @@ func (li *LazyIdentity) Keys() ([]*identity.Key, error) { return id.Keys(), nil } -func (li *LazyIdentity) ValidKeysAtTime(time lamport.Time) ([]*identity.Key, error) { +func (li *lazyIdentity) ValidKeysAtTime(time lamport.Time) ([]*identity.Key, error) { id, err := li.load() if err != nil { return nil, err @@ -97,11 +100,11 @@ func (li *LazyIdentity) ValidKeysAtTime(time lamport.Time) ([]*identity.Key, err return id.ValidKeysAtTime(time), nil } -func (li *LazyIdentity) DisplayName() string { +func (li *lazyIdentity) DisplayName() string { return li.excerpt.DisplayName() } -func (li *LazyIdentity) IsProtected() (bool, error) { +func (li *lazyIdentity) IsProtected() (bool, error) { id, err := li.load() if err != nil { return false, err @@ -109,7 +112,7 @@ func (li *LazyIdentity) IsProtected() (bool, error) { return id.IsProtected(), nil } -func (li *LazyIdentity) LastModificationLamport() (lamport.Time, error) { +func (li *lazyIdentity) LastModificationLamport() (lamport.Time, error) { id, err := li.load() if err != nil { return 0, err @@ -117,7 +120,7 @@ func (li *LazyIdentity) LastModificationLamport() (lamport.Time, error) { return id.LastModificationLamport(), nil } -func (li *LazyIdentity) LastModification() (timestamp.Timestamp, error) { +func (li *lazyIdentity) LastModification() (timestamp.Timestamp, error) { id, err := li.load() if err != nil { return 0, err @@ -125,40 +128,40 @@ func (li *LazyIdentity) LastModification() (timestamp.Timestamp, error) { return id.LastModification(), nil } -var _ IdentityWrapper = &LoadedIdentity{} +var _ IdentityWrapper = &loadedIdentity{} -type LoadedIdentity struct { +type loadedIdentity struct { identity.Interface } -func NewLoadedIdentity(id identity.Interface) *LoadedIdentity { - return &LoadedIdentity{Interface: id} +func NewLoadedIdentity(id identity.Interface) *loadedIdentity { + return &loadedIdentity{Interface: id} } -func (l LoadedIdentity) Email() (string, error) { +func (l loadedIdentity) Email() (string, error) { return l.Interface.Email(), nil } -func (l LoadedIdentity) AvatarUrl() (string, error) { +func (l loadedIdentity) AvatarUrl() (string, error) { return l.Interface.AvatarUrl(), nil } -func (l LoadedIdentity) Keys() ([]*identity.Key, error) { +func (l loadedIdentity) Keys() ([]*identity.Key, error) { return l.Interface.Keys(), nil } -func (l LoadedIdentity) ValidKeysAtTime(time lamport.Time) ([]*identity.Key, error) { +func (l loadedIdentity) ValidKeysAtTime(time lamport.Time) ([]*identity.Key, error) { return l.Interface.ValidKeysAtTime(time), nil } -func (l LoadedIdentity) IsProtected() (bool, error) { +func (l loadedIdentity) IsProtected() (bool, error) { return l.Interface.IsProtected(), nil } -func (l LoadedIdentity) LastModificationLamport() (lamport.Time, error) { +func (l loadedIdentity) LastModificationLamport() (lamport.Time, error) { return l.Interface.LastModificationLamport(), nil } -func (l LoadedIdentity) LastModification() (timestamp.Timestamp, error) { +func (l loadedIdentity) LastModification() (timestamp.Timestamp, error) { return l.Interface.LastModification(), nil } |