CasaOS/service/service.go

143 lines
3.2 KiB
Go
Raw Normal View History

/*
* @Author: LinkLeong link@icewhale.com
* @Date: 2022-07-12 09:48:56
* @LastEditors: LinkLeong
* @LastEditTime: 2022-09-02 22:10:05
* @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 (
"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"
"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"
)
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
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 {
// User() UserService
Casa() CasaService
2021-09-26 02:35:02 +00:00
Notify() NotifyServer
Rely() RelyService
System() SystemService
Shares() SharesService
Connections() ConnectionsService
Gateway() external.ManagementService
2023-01-16 05:54:44 +00:00
Storage() StorageService
Storages() StoragesService
StoragePath() StoragePathService
FsListService() FsListService
2023-02-02 03:36:59 +00:00
FsLinkService() FsLinkService
2023-01-16 05:54:44 +00:00
FsService() FsService
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
gatewayManagement, err := external.NewManagementService(RuntimePath)
if err != nil && len(RuntimePath) > 0 {
panic(err)
}
2021-09-26 02:35:02 +00:00
return &store{
2023-01-16 05:54:44 +00:00
gateway: gatewayManagement,
casa: NewCasaService(),
notify: NewNotifyService(db),
rely: NewRelyService(db),
system: NewSystemService(),
shares: NewSharesService(db),
connections: NewConnectionsService(db),
2023-02-02 03:36:59 +00:00
storage: NewStorageService(),
2023-01-16 05:54:44 +00:00
storages: NewStoragesService(),
storage_path: NewStoragePathService(),
fs_list: NewFsListService(),
2023-02-02 03:36:59 +00:00
fs_link: NewFsLinkService(),
2023-01-16 05:54:44 +00:00
fs: NewFsService(),
2021-09-26 02:35:02 +00:00
}
}
type store struct {
2023-01-16 05:54:44 +00:00
db *gorm.DB
casa CasaService
notify NotifyServer
rely RelyService
system SystemService
shares SharesService
connections ConnectionsService
gateway external.ManagementService
storage StorageService
storages StoragesService
storage_path StoragePathService
fs_list FsListService
2023-02-02 03:36:59 +00:00
fs_link FsLinkService
2023-01-16 05:54:44 +00:00
fs FsService
}
2023-02-02 03:36:59 +00:00
func (c *store) FsLinkService() FsLinkService {
return c.fs_link
}
2023-01-16 05:54:44 +00:00
func (c *store) FsService() FsService {
return c.fs
}
func (c *store) FsListService() FsListService {
return c.fs_list
}
func (c *store) StoragePath() StoragePathService {
return c.storage_path
}
func (c *store) Storages() StoragesService {
return c.storages
}
func (c *store) Storage() StorageService {
return c.storage
}
func (c *store) Gateway() external.ManagementService {
return c.gateway
}
func (s *store) Connections() ConnectionsService {
return s.connections
}
func (s *store) Shares() SharesService {
return s.shares
2021-09-26 02:35:02 +00:00
}
func (c *store) Rely() RelyService {
return c.rely
}
2021-09-26 02:35:02 +00:00
func (c *store) System() SystemService {
return c.system
}
func (c *store) Notify() NotifyServer {
2021-09-26 02:35:02 +00:00
return c.notify
}
func (c *store) Casa() CasaService {
return c.casa
2021-09-26 02:35:02 +00:00
}