2022-07-22 03:02:11 +00:00
|
|
|
/*
|
|
|
|
* @Author: LinkLeong link@icewhale.com
|
|
|
|
* @Date: 2022-07-12 09:48:56
|
|
|
|
* @LastEditors: LinkLeong
|
2022-09-06 06:28:49 +00:00
|
|
|
* @LastEditTime: 2022-09-02 22:10:05
|
2022-07-22 03:02:11 +00:00
|
|
|
* @FilePath: /CasaOS/service/service.go
|
|
|
|
* @Description:
|
|
|
|
* @Website: https://www.casaos.io
|
|
|
|
* Copyright (c) 2022 by icewhale, All Rights Reserved.
|
|
|
|
*/
|
2021-09-26 02:35:02 +00:00
|
|
|
package service
|
|
|
|
|
|
|
|
import (
|
2022-10-28 21:34:18 +00:00
|
|
|
"github.com/IceWhaleTech/CasaOS-Common/external"
|
2022-12-20 06:05:16 +00:00
|
|
|
"github.com/IceWhaleTech/CasaOS-Common/utils/logger"
|
|
|
|
socketio "github.com/googollee/go-socket.io"
|
2022-02-17 10:43:25 +00:00
|
|
|
"github.com/gorilla/websocket"
|
2021-10-29 10:37:27 +00:00
|
|
|
"github.com/patrickmn/go-cache"
|
2022-12-20 06:05:16 +00:00
|
|
|
"go.uber.org/zap"
|
2021-09-26 02:35:02 +00:00
|
|
|
"gorm.io/gorm"
|
|
|
|
)
|
|
|
|
|
2021-10-29 10:37:27 +00:00
|
|
|
var Cache *cache.Cache
|
|
|
|
|
2021-09-26 02:35:02 +00:00
|
|
|
var MyService Repository
|
2022-12-20 06:05:16 +00:00
|
|
|
var SocketServer *socketio.Server
|
2022-11-29 17:17:14 +00:00
|
|
|
var (
|
|
|
|
WebSocketConns []*websocket.Conn
|
|
|
|
SocketRun bool
|
|
|
|
)
|
2022-02-17 10:43:25 +00:00
|
|
|
|
2021-09-26 02:35:02 +00:00
|
|
|
type Repository interface {
|
2022-11-29 17:17:14 +00:00
|
|
|
// User() UserService
|
2022-03-09 08:37:03 +00:00
|
|
|
Casa() CasaService
|
2021-09-26 02:35:02 +00:00
|
|
|
Notify() NotifyServer
|
|
|
|
Rely() RelyService
|
|
|
|
System() SystemService
|
2022-08-15 03:37:21 +00:00
|
|
|
Shares() SharesService
|
|
|
|
Connections() ConnectionsService
|
2022-10-28 21:34:18 +00:00
|
|
|
Gateway() external.ManagementService
|
2021-09-26 02:35:02 +00:00
|
|
|
}
|
|
|
|
|
2022-12-20 06:05:16 +00:00
|
|
|
func NewService(db *gorm.DB, RuntimePath string, socket *socketio.Server) Repository {
|
|
|
|
if socket == nil {
|
|
|
|
logger.Error("socket is nil", zap.Any("error", "socket is nil"))
|
|
|
|
}
|
|
|
|
SocketServer = socket
|
2022-10-28 21:34:18 +00:00
|
|
|
gatewayManagement, err := external.NewManagementService(RuntimePath)
|
2022-09-06 06:28:49 +00:00
|
|
|
if err != nil && len(RuntimePath) > 0 {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
|
2021-09-26 02:35:02 +00:00
|
|
|
return &store{
|
2022-09-06 06:28:49 +00:00
|
|
|
gateway: gatewayManagement,
|
2022-08-15 03:37:21 +00:00
|
|
|
casa: NewCasaService(),
|
|
|
|
notify: NewNotifyService(db),
|
|
|
|
rely: NewRelyService(db),
|
|
|
|
system: NewSystemService(),
|
|
|
|
shares: NewSharesService(db),
|
|
|
|
connections: NewConnectionsService(db),
|
2021-09-26 02:35:02 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
type store struct {
|
2022-08-15 03:37:21 +00:00
|
|
|
db *gorm.DB
|
|
|
|
casa CasaService
|
|
|
|
notify NotifyServer
|
|
|
|
rely RelyService
|
|
|
|
system SystemService
|
|
|
|
shares SharesService
|
|
|
|
connections ConnectionsService
|
2022-10-28 21:34:18 +00:00
|
|
|
gateway external.ManagementService
|
2022-08-15 03:37:21 +00:00
|
|
|
}
|
|
|
|
|
2022-10-28 21:34:18 +00:00
|
|
|
func (c *store) Gateway() external.ManagementService {
|
2022-09-06 06:28:49 +00:00
|
|
|
return c.gateway
|
|
|
|
}
|
2022-11-29 17:17:14 +00:00
|
|
|
|
2022-08-15 03:37:21 +00:00
|
|
|
func (s *store) Connections() ConnectionsService {
|
|
|
|
return s.connections
|
|
|
|
}
|
2022-11-29 17:17:14 +00:00
|
|
|
|
2022-08-15 03:37:21 +00:00
|
|
|
func (s *store) Shares() SharesService {
|
|
|
|
return s.shares
|
2021-09-26 02:35:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (c *store) Rely() RelyService {
|
|
|
|
return c.rely
|
|
|
|
}
|
2022-07-22 03:02:11 +00:00
|
|
|
|
2021-09-26 02:35:02 +00:00
|
|
|
func (c *store) System() SystemService {
|
|
|
|
return c.system
|
|
|
|
}
|
|
|
|
|
2022-11-29 17:17:14 +00:00
|
|
|
func (c *store) Notify() NotifyServer {
|
2021-09-26 02:35:02 +00:00
|
|
|
return c.notify
|
|
|
|
}
|
|
|
|
|
2022-03-09 08:37:03 +00:00
|
|
|
func (c *store) Casa() CasaService {
|
|
|
|
return c.casa
|
2021-09-26 02:35:02 +00:00
|
|
|
}
|