mirror of
https://github.com/khairul169/vaulterm.git
synced 2026-09-15 17:03:30 +07:00
feat: add hosts management
This commit is contained in:
@@ -8,16 +8,16 @@ import (
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
type BaseModel struct {
|
||||
type Model struct {
|
||||
ID string `gorm:"primarykey;type:varchar(26)" json:"id"`
|
||||
}
|
||||
|
||||
func (m *BaseModel) BeforeCreate(tx *gorm.DB) error {
|
||||
func (m *Model) BeforeCreate(tx *gorm.DB) error {
|
||||
m.ID = m.GenerateID()
|
||||
return nil
|
||||
}
|
||||
|
||||
func (m *BaseModel) GenerateID() string {
|
||||
func (m *Model) GenerateID() string {
|
||||
return strings.ToLower(ulid.Make().String())
|
||||
}
|
||||
|
||||
|
||||
@@ -12,7 +12,7 @@ const (
|
||||
)
|
||||
|
||||
type Host struct {
|
||||
BaseModel
|
||||
Model
|
||||
|
||||
Type string `json:"type" gorm:"not null;index:hosts_type_idx;type:varchar(16)"`
|
||||
Label string `json:"label"`
|
||||
@@ -23,9 +23,9 @@ type Host struct {
|
||||
ParentID *string `json:"parentId" gorm:"index:hosts_parent_id_idx;type:varchar(26)"`
|
||||
Parent *Host `json:"parent" gorm:"foreignKey:ParentID"`
|
||||
KeyID *string `json:"keyId" gorm:"index:hosts_key_id_idx"`
|
||||
Key Keychain `gorm:"foreignKey:KeyID"`
|
||||
Key Keychain `json:"key" gorm:"foreignKey:KeyID"`
|
||||
AltKeyID *string `json:"altKeyId" gorm:"index:hosts_altkey_id_idx"`
|
||||
AltKey Keychain `gorm:"foreignKey:AltKeyID"`
|
||||
AltKey Keychain `json:"altKey" gorm:"foreignKey:AltKeyID"`
|
||||
|
||||
Timestamps
|
||||
SoftDeletes
|
||||
|
||||
@@ -13,7 +13,7 @@ const (
|
||||
)
|
||||
|
||||
type Keychain struct {
|
||||
BaseModel
|
||||
Model
|
||||
|
||||
Label string `json:"label"`
|
||||
Type string `json:"type" gorm:"not null;index:keychains_type_idx;type:varchar(12)"`
|
||||
|
||||
@@ -6,7 +6,7 @@ const (
|
||||
)
|
||||
|
||||
type User struct {
|
||||
BaseModel
|
||||
Model
|
||||
|
||||
Name string `json:"name"`
|
||||
Username string `json:"username" gorm:"unique"`
|
||||
|
||||
Reference in New Issue
Block a user