init: first steps

This commit is contained in:
2025-07-20 23:50:47 +03:00
commit 5f26ad6941
25 changed files with 1134 additions and 0 deletions

34
model/service.go Normal file
View File

@@ -0,0 +1,34 @@
package model
type HTTPConfig struct {
Authorization string `json:"authorization"`
}
type ServiceTypeCheckConfig struct {
Version string `json:"version"`
HTTPConfig *HTTPConfig `json:"http_config"`
}
type Service struct {
// Unique ID for entity
ID int `gorm:"primary_key;auto_increment" json:"id"`
// Human-readable service name
Name string `gorm:"size:255;not null" json:"name"`
// Human-readable service description
Description string `gorm:"size:255" json:"description"`
PublicDescription string `gorm:"size:255" json:"public_description"`
Public *bool `gorm:"default:false" json:"public"`
// Host to check, for example 192.168.1.44
Host string `gorm:"size:255;not null" json:"host"`
// Port to check, for example 5432 (postgresql)
Port *int `gorm:"default:null" json:"port"`
// Type for check, for now is TCP or HTTP
Type string `gorm:"size:255;not null" json:"type"`
TypeConfig *ServiceTypeCheckConfig `gorm:"serializer:json" json:"type_config"`
Statuses []Status `gorm:"foreignkey:ServiceID" json:"statuses"`
}
func (Service) TableName() string {
return "service"
}

25
model/status.go Normal file
View File

@@ -0,0 +1,25 @@
package model
import (
"time"
"gorm.io/gorm"
)
type Status struct {
ID int `gorm:"primary_key;auto_increment" json:"-"`
ServiceID int `gorm:"one" json:"-"`
Status string `gorm:"size:255;not null" json:"status"`
Description *string `gorm:"size:255" json:"description"`
CreatedAt time.Time `json:"created_at"`
}
func (Status) TableName() string {
return "status"
}
func (s *Status) BeforeCreate(*gorm.DB) error {
s.CreatedAt = time.Now()
return nil
}