diff options
author | Thomas Boerger <thomas@webhippie.de> | 2016-11-27 12:13:43 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-11-27 12:13:43 +0100 |
commit | e23a9d22e5ea87d2141680501708ec03fda040f8 (patch) | |
tree | 545502cabe99bedfb3da0bc02784f7807ff83efb | |
parent | 93d527a0a4d39142c879d5faf3c295c629e831bb (diff) | |
parent | 6cde041080ad503216784d513770a3683243a14b (diff) | |
download | gitea-e23a9d22e5ea87d2141680501708ec03fda040f8.tar.gz gitea-e23a9d22e5ea87d2141680501708ec03fda040f8.zip |
Merge pull request #267 from Bwko/lint/ssh_key
Lint models/ssh_key.go
-rw-r--r-- | models/ssh_key.go | 55 |
1 files changed, 32 insertions, 23 deletions
diff --git a/models/ssh_key.go b/models/ssh_key.go index 98fb2dcdbf..53a31f6f8d 100644 --- a/models/ssh_key.go +++ b/models/ssh_key.go @@ -33,10 +33,13 @@ const ( var sshOpLocker sync.Mutex +// KeyType specifies the key type type KeyType int const ( + // KeyTypeUser specifies the user key KeyTypeUser = iota + 1 + // KeyTypeDeploy specifies the deploy key KeyTypeDeploy ) @@ -58,28 +61,31 @@ type PublicKey struct { HasUsed bool `xorm:"-"` } -func (k *PublicKey) BeforeInsert() { - k.CreatedUnix = time.Now().Unix() +// BeforeInsert will be invoked by XORM before inserting a record +func (key *PublicKey) BeforeInsert() { + key.CreatedUnix = time.Now().Unix() } -func (k *PublicKey) BeforeUpdate() { - k.UpdatedUnix = time.Now().Unix() +// BeforeUpdate is invoked from XORM before updating this object. +func (key *PublicKey) BeforeUpdate() { + key.UpdatedUnix = time.Now().Unix() } -func (k *PublicKey) AfterSet(colName string, _ xorm.Cell) { +// AfterSet is invoked from XORM after setting the value of a field of this object. +func (key *PublicKey) AfterSet(colName string, _ xorm.Cell) { switch colName { case "created_unix": - k.Created = time.Unix(k.CreatedUnix, 0).Local() + key.Created = time.Unix(key.CreatedUnix, 0).Local() case "updated_unix": - k.Updated = time.Unix(k.UpdatedUnix, 0).Local() - k.HasUsed = k.Updated.After(k.Created) - k.HasRecentActivity = k.Updated.Add(7 * 24 * time.Hour).After(time.Now()) + key.Updated = time.Unix(key.UpdatedUnix, 0).Local() + key.HasUsed = key.Updated.After(key.Created) + key.HasRecentActivity = key.Updated.Add(7 * 24 * time.Hour).After(time.Now()) } } // OmitEmail returns content of public key without email address. -func (k *PublicKey) OmitEmail() string { - return strings.Join(strings.Split(k.Content, " ")[:2], " ") +func (key *PublicKey) OmitEmail() string { + return strings.Join(strings.Split(key.Content, " ")[:2], " ") } // AuthorizedString returns formatted public key string for authorized_keys file. @@ -573,32 +579,35 @@ type DeployKey struct { HasUsed bool `xorm:"-"` } -func (k *DeployKey) BeforeInsert() { - k.CreatedUnix = time.Now().Unix() +// BeforeInsert will be invoked by XORM before inserting a record +func (key *DeployKey) BeforeInsert() { + key.CreatedUnix = time.Now().Unix() } -func (k *DeployKey) BeforeUpdate() { - k.UpdatedUnix = time.Now().Unix() +// BeforeUpdate is invoked from XORM before updating this object. +func (key *DeployKey) BeforeUpdate() { + key.UpdatedUnix = time.Now().Unix() } -func (k *DeployKey) AfterSet(colName string, _ xorm.Cell) { +// AfterSet is invoked from XORM after setting the value of a field of this object. +func (key *DeployKey) AfterSet(colName string, _ xorm.Cell) { switch colName { case "created_unix": - k.Created = time.Unix(k.CreatedUnix, 0).Local() + key.Created = time.Unix(key.CreatedUnix, 0).Local() case "updated_unix": - k.Updated = time.Unix(k.UpdatedUnix, 0).Local() - k.HasUsed = k.Updated.After(k.Created) - k.HasRecentActivity = k.Updated.Add(7 * 24 * time.Hour).After(time.Now()) + key.Updated = time.Unix(key.UpdatedUnix, 0).Local() + key.HasUsed = key.Updated.After(key.Created) + key.HasRecentActivity = key.Updated.Add(7 * 24 * time.Hour).After(time.Now()) } } // GetContent gets associated public key content. -func (k *DeployKey) GetContent() error { - pkey, err := GetPublicKeyByID(k.KeyID) +func (key *DeployKey) GetContent() error { + pkey, err := GetPublicKeyByID(key.KeyID) if err != nil { return err } - k.Content = pkey.Content + key.Content = pkey.Content return nil } |