feat: add hosts management

This commit is contained in:
2024-11-09 10:33:07 +00:00
parent 31c43836f4
commit d931235fb3
27 changed files with 742 additions and 94 deletions
+3 -3
View File
@@ -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())
}
+3 -3
View File
@@ -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
+1 -1
View File
@@ -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)"`
+1 -1
View File
@@ -6,7 +6,7 @@ const (
)
type User struct {
BaseModel
Model
Name string `json:"name"`
Username string `json:"username" gorm:"unique"`