Skip to content

Commit e23a9d2

Browse files
authored
Merge pull request #267 from Bwko/lint/ssh_key
Lint models/ssh_key.go
2 parents 93d527a + 6cde041 commit e23a9d2

File tree

1 file changed

+32
-23
lines changed

1 file changed

+32
-23
lines changed

models/ssh_key.go

Lines changed: 32 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,13 @@ const (
3333

3434
var sshOpLocker sync.Mutex
3535

36+
// KeyType specifies the key type
3637
type KeyType int
3738

3839
const (
40+
// KeyTypeUser specifies the user key
3941
KeyTypeUser = iota + 1
42+
// KeyTypeDeploy specifies the deploy key
4043
KeyTypeDeploy
4144
)
4245

@@ -58,28 +61,31 @@ type PublicKey struct {
5861
HasUsed bool `xorm:"-"`
5962
}
6063

61-
func (k *PublicKey) BeforeInsert() {
62-
k.CreatedUnix = time.Now().Unix()
64+
// BeforeInsert will be invoked by XORM before inserting a record
65+
func (key *PublicKey) BeforeInsert() {
66+
key.CreatedUnix = time.Now().Unix()
6367
}
6468

65-
func (k *PublicKey) BeforeUpdate() {
66-
k.UpdatedUnix = time.Now().Unix()
69+
// BeforeUpdate is invoked from XORM before updating this object.
70+
func (key *PublicKey) BeforeUpdate() {
71+
key.UpdatedUnix = time.Now().Unix()
6772
}
6873

69-
func (k *PublicKey) AfterSet(colName string, _ xorm.Cell) {
74+
// AfterSet is invoked from XORM after setting the value of a field of this object.
75+
func (key *PublicKey) AfterSet(colName string, _ xorm.Cell) {
7076
switch colName {
7177
case "created_unix":
72-
k.Created = time.Unix(k.CreatedUnix, 0).Local()
78+
key.Created = time.Unix(key.CreatedUnix, 0).Local()
7379
case "updated_unix":
74-
k.Updated = time.Unix(k.UpdatedUnix, 0).Local()
75-
k.HasUsed = k.Updated.After(k.Created)
76-
k.HasRecentActivity = k.Updated.Add(7 * 24 * time.Hour).After(time.Now())
80+
key.Updated = time.Unix(key.UpdatedUnix, 0).Local()
81+
key.HasUsed = key.Updated.After(key.Created)
82+
key.HasRecentActivity = key.Updated.Add(7 * 24 * time.Hour).After(time.Now())
7783
}
7884
}
7985

8086
// OmitEmail returns content of public key without email address.
81-
func (k *PublicKey) OmitEmail() string {
82-
return strings.Join(strings.Split(k.Content, " ")[:2], " ")
87+
func (key *PublicKey) OmitEmail() string {
88+
return strings.Join(strings.Split(key.Content, " ")[:2], " ")
8389
}
8490

8591
// AuthorizedString returns formatted public key string for authorized_keys file.
@@ -573,32 +579,35 @@ type DeployKey struct {
573579
HasUsed bool `xorm:"-"`
574580
}
575581

576-
func (k *DeployKey) BeforeInsert() {
577-
k.CreatedUnix = time.Now().Unix()
582+
// BeforeInsert will be invoked by XORM before inserting a record
583+
func (key *DeployKey) BeforeInsert() {
584+
key.CreatedUnix = time.Now().Unix()
578585
}
579586

580-
func (k *DeployKey) BeforeUpdate() {
581-
k.UpdatedUnix = time.Now().Unix()
587+
// BeforeUpdate is invoked from XORM before updating this object.
588+
func (key *DeployKey) BeforeUpdate() {
589+
key.UpdatedUnix = time.Now().Unix()
582590
}
583591

584-
func (k *DeployKey) AfterSet(colName string, _ xorm.Cell) {
592+
// AfterSet is invoked from XORM after setting the value of a field of this object.
593+
func (key *DeployKey) AfterSet(colName string, _ xorm.Cell) {
585594
switch colName {
586595
case "created_unix":
587-
k.Created = time.Unix(k.CreatedUnix, 0).Local()
596+
key.Created = time.Unix(key.CreatedUnix, 0).Local()
588597
case "updated_unix":
589-
k.Updated = time.Unix(k.UpdatedUnix, 0).Local()
590-
k.HasUsed = k.Updated.After(k.Created)
591-
k.HasRecentActivity = k.Updated.Add(7 * 24 * time.Hour).After(time.Now())
598+
key.Updated = time.Unix(key.UpdatedUnix, 0).Local()
599+
key.HasUsed = key.Updated.After(key.Created)
600+
key.HasRecentActivity = key.Updated.Add(7 * 24 * time.Hour).After(time.Now())
592601
}
593602
}
594603

595604
// GetContent gets associated public key content.
596-
func (k *DeployKey) GetContent() error {
597-
pkey, err := GetPublicKeyByID(k.KeyID)
605+
func (key *DeployKey) GetContent() error {
606+
pkey, err := GetPublicKeyByID(key.KeyID)
598607
if err != nil {
599608
return err
600609
}
601-
k.Content = pkey.Content
610+
key.Content = pkey.Content
602611
return nil
603612
}
604613

0 commit comments

Comments
 (0)