2025-07-24 05:06:14 +00:00
|
|
|
package service
|
|
|
|
|
|
|
|
|
|
import (
|
2025-09-25 13:37:50 +00:00
|
|
|
"github.com/mhsanaei/3x-ui/v2/database"
|
|
|
|
|
"github.com/mhsanaei/3x-ui/v2/database/model"
|
2025-07-24 05:06:14 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
type MultiServerService struct{}
|
|
|
|
|
|
|
|
|
|
func (s *MultiServerService) GetServers() ([]*model.Server, error) {
|
|
|
|
|
db := database.GetDB()
|
|
|
|
|
var servers []*model.Server
|
|
|
|
|
err := db.Find(&servers).Error
|
|
|
|
|
return servers, err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (s *MultiServerService) GetServer(id int) (*model.Server, error) {
|
|
|
|
|
db := database.GetDB()
|
|
|
|
|
var server model.Server
|
|
|
|
|
err := db.First(&server, id).Error
|
|
|
|
|
return &server, err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (s *MultiServerService) AddServer(server *model.Server) error {
|
|
|
|
|
db := database.GetDB()
|
|
|
|
|
return db.Create(server).Error
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (s *MultiServerService) UpdateServer(server *model.Server) error {
|
|
|
|
|
db := database.GetDB()
|
|
|
|
|
return db.Save(server).Error
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (s *MultiServerService) DeleteServer(id int) error {
|
|
|
|
|
db := database.GetDB()
|
|
|
|
|
return db.Delete(&model.Server{}, id).Error
|
|
|
|
|
}
|