aboutsummaryrefslogtreecommitdiffstats
path: root/models/token.go
diff options
context:
space:
mode:
authorLunny Xiao <xiaolunwen@gmail.com>2017-10-02 00:52:35 +0800
committerLauris BH <lauris@nix.lv>2017-10-01 19:52:35 +0300
commita8717e5e3ace4dd226547faae9c3a44616bbf6f0 (patch)
tree524dc024dec64131406486556951a53655ad8510 /models/token.go
parent1ad902d5298202d5be14fd5a9c8ed6ce781a23c8 (diff)
downloadgitea-a8717e5e3ace4dd226547faae9c3a44616bbf6f0.tar.gz
gitea-a8717e5e3ace4dd226547faae9c3a44616bbf6f0.zip
Use AfterLoad instead of AfterSet on Structs (#2628)
* use AfterLoad instead of AfterSet on Structs * fix the comments on AfterLoad * fix the comments on action AfterLoad
Diffstat (limited to 'models/token.go')
-rw-r--r--models/token.go19
1 files changed, 7 insertions, 12 deletions
diff --git a/models/token.go b/models/token.go
index d4b86eb3ae..5053214b6e 100644
--- a/models/token.go
+++ b/models/token.go
@@ -7,7 +7,6 @@ package models
import (
"time"
- "github.com/go-xorm/xorm"
gouuid "github.com/satori/go.uuid"
"code.gitea.io/gitea/modules/base"
@@ -22,22 +21,18 @@ type AccessToken struct {
Created time.Time `xorm:"-"`
CreatedUnix int64 `xorm:"INDEX created"`
- Updated time.Time `xorm:"-"` // Note: Updated must below Created for AfterSet.
+ Updated time.Time `xorm:"-"`
UpdatedUnix int64 `xorm:"INDEX updated"`
HasRecentActivity bool `xorm:"-"`
HasUsed bool `xorm:"-"`
}
-// AfterSet is invoked from XORM after setting the value of a field of this object.
-func (t *AccessToken) AfterSet(colName string, _ xorm.Cell) {
- switch colName {
- case "created_unix":
- t.Created = time.Unix(t.CreatedUnix, 0).Local()
- case "updated_unix":
- t.Updated = time.Unix(t.UpdatedUnix, 0).Local()
- t.HasUsed = t.Updated.After(t.Created)
- t.HasRecentActivity = t.Updated.Add(7 * 24 * time.Hour).After(time.Now())
- }
+// AfterLoad is invoked from XORM after setting the values of all fields of this object.
+func (t *AccessToken) AfterLoad() {
+ t.Created = time.Unix(t.CreatedUnix, 0).Local()
+ t.Updated = time.Unix(t.UpdatedUnix, 0).Local()
+ t.HasUsed = t.Updated.After(t.Created)
+ t.HasRecentActivity = t.Updated.Add(7 * 24 * time.Hour).After(time.Now())
}
// NewAccessToken creates new access token.