diff options
author | Michael Muré <michael.mure@consensys.net> | 2019-02-01 12:22:00 +0100 |
---|---|---|
committer | Michael Muré <batolettre@gmail.com> | 2019-03-01 22:40:22 +0100 |
commit | 56c6147eb6012252cf0b723b9eb6d1e841fc2f94 (patch) | |
tree | cce638adbf4a7d5b424fe9682cafc2fea5c64785 /identity/identity_stub.go | |
parent | 14b240af8fef269d2c1d5dde2fff192b656c50f3 (diff) | |
download | git-bug-56c6147eb6012252cf0b723b9eb6d1e841fc2f94.tar.gz |
identity: more refactoring progress
Diffstat (limited to 'identity/identity_stub.go')
-rw-r--r-- | identity/identity_stub.go | 85 |
1 files changed, 85 insertions, 0 deletions
diff --git a/identity/identity_stub.go b/identity/identity_stub.go new file mode 100644 index 00000000..0163e9d4 --- /dev/null +++ b/identity/identity_stub.go @@ -0,0 +1,85 @@ +package identity + +import ( + "encoding/json" + + "github.com/MichaelMure/git-bug/repository" + "github.com/MichaelMure/git-bug/util/lamport" +) + +var _ Interface = &IdentityStub{} + +// IdentityStub is an almost empty Identity, holding only the id. +// When a normal Identity is serialized into JSON, only the id is serialized. +// All the other data are stored in git in a chain of commit + a ref. +// When this JSON is deserialized, an IdentityStub is returned instead, to be replaced +// later by the proper Identity, loaded from the Repo. +type IdentityStub struct { + id string +} + +func (i *IdentityStub) MarshalJSON() ([]byte, error) { + return json.Marshal(struct { + Id string `json:"id"` + }{ + Id: i.id, + }) +} + +func (i *IdentityStub) UnmarshalJSON(data []byte) error { + aux := struct { + Id string `json:"id"` + }{} + + if err := json.Unmarshal(data, &aux); err != nil { + return err + } + + i.id = aux.Id + + return nil +} + +func (i *IdentityStub) Id() string { + return i.id +} + +func (IdentityStub) Name() string { + panic("identities needs to be properly loaded with identity.Read()") +} + +func (IdentityStub) Email() string { + panic("identities needs to be properly loaded with identity.Read()") +} + +func (IdentityStub) Login() string { + panic("identities needs to be properly loaded with identity.Read()") +} + +func (IdentityStub) AvatarUrl() string { + panic("identities needs to be properly loaded with identity.Read()") +} + +func (IdentityStub) Keys() []Key { + panic("identities needs to be properly loaded with identity.Read()") +} + +func (IdentityStub) ValidKeysAtTime(time lamport.Time) []Key { + panic("identities needs to be properly loaded with identity.Read()") +} + +func (IdentityStub) DisplayName() string { + panic("identities needs to be properly loaded with identity.Read()") +} + +func (IdentityStub) Validate() error { + panic("identities needs to be properly loaded with identity.Read()") +} + +func (IdentityStub) Commit(repo repository.Repo) error { + panic("identities needs to be properly loaded with identity.Read()") +} + +func (IdentityStub) IsProtected() bool { + panic("identities needs to be properly loaded with identity.Read()") +} |