From 6cde041080ad503216784d513770a3683243a14b Mon Sep 17 00:00:00 2001 From: Bwko Date: Sat, 26 Nov 2016 01:36:03 +0100 Subject: [PATCH] Lint models/ssh_key.go --- models/ssh_key.go | 55 +++++++++++++++++++++++++++-------------------- 1 file 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 }