add comments, code refactor

This commit is contained in:
MaysWind
2020-12-23 01:12:57 +08:00
parent 995eeae041
commit 62ef7cbcbe
11 changed files with 115 additions and 8 deletions
+9
View File
@@ -2,8 +2,10 @@ package models
import "github.com/mayswind/lab/pkg/core"
// The maximum size of user agent stored in database
const TOKEN_USER_AGENT_MAX_LENGTH = 255
// TokenRecord represents token data stored in database
type TokenRecord struct {
Uid int64 `xorm:"PK INDEX(IDX_token_record_uid_type_expired_time)"`
UserTokenId int64 `xorm:"PK"`
@@ -14,16 +16,19 @@ type TokenRecord struct {
ExpiredUnixTime int64 `xorm:"INDEX(IDX_token_record_uid_type_expired_time)"`
}
// TokenRevokeRequest represents all parameters of token revoking request
type TokenRevokeRequest struct {
TokenId string `json:"tokenId" binding:"required,notBlank"`
}
// TokenRefreshResponse represents all parameters of token refreshing request
type TokenRefreshResponse struct {
NewToken string `json:"newToken"`
OldTokenId string `json:"oldTokenId"`
User *UserBasicInfo `json:"user"`
}
// TokenInfoResponse represents a view-object of token
type TokenInfoResponse struct {
TokenId string `json:"tokenId"`
TokenType core.TokenType `json:"tokenType"`
@@ -33,16 +38,20 @@ type TokenInfoResponse struct {
IsCurrent bool `json:"isCurrent"`
}
// TokenInfoResponseSlice represents the slice data structure of TokenInfoResponse
type TokenInfoResponseSlice []*TokenInfoResponse
// Len returns the count of items
func (a TokenInfoResponseSlice) Len() int {
return len(a)
}
// Swap swaps two items
func (a TokenInfoResponseSlice) Swap(i, j int) {
a[i], a[j] = a[j], a[i]
}
// Less reports whether the first item is less than the second one
func (a TokenInfoResponseSlice) Less(i, j int) bool {
return a[i].ExpiredAt > a[j].ExpiredAt
}