forked from davecheney/pub
-
Notifications
You must be signed in to change notification settings - Fork 0
/
token.go
37 lines (32 loc) · 968 Bytes
/
token.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
package models
import (
"time"
"github.com/bardic/pub/internal/snowflake"
"gorm.io/gorm"
"gorm.io/gorm/schema"
)
// A Token is an access token for an Application.
// A Token belongs to an Account.
// A Token belongs to an Application.
type Token struct {
AccessToken string `gorm:"size:64;primaryKey;autoIncrement:false"`
CreatedAt time.Time
AccountID *snowflake.ID
Account *Account `gorm:"constraint:OnDelete:CASCADE;<-:false;"`
ApplicationID snowflake.ID
Application *Application `gorm:"constraint:OnDelete:CASCADE;<-:false;"`
TokenType `gorm:"not null"`
Scope string `gorm:"size:64;not null"`
AuthorizationCode string `gorm:"size:64;not null"`
}
type TokenType string
func (TokenType) GormDBDataType(db *gorm.DB, field *schema.Field) string {
switch db.Dialector.Name() {
case "mysql", "postgres":
return "enum('Bearer')"
case "sqlite":
return "TEXT"
default:
return ""
}
}