style(be):拆分模块目录
This commit is contained in:
parent
d21b8cca60
commit
8e7bd69312
2
.github/workflows/golangci-lint.yml
vendored
2
.github/workflows/golangci-lint.yml
vendored
@ -19,4 +19,4 @@ jobs:
|
||||
with:
|
||||
# Optional: version of golangci-lint to use in form of v1.2 or v1.2.3 or `latest` to use the latest version
|
||||
version: v1.29
|
||||
args: --timeout=10m
|
||||
args: --timeout=5m
|
||||
|
12
main.go
12
main.go
@ -3,9 +3,11 @@ package main
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"next-terminal/pkg/config"
|
||||
"next-terminal/pkg/global"
|
||||
"next-terminal/pkg/task"
|
||||
"next-terminal/server/api"
|
||||
"next-terminal/server/config"
|
||||
"next-terminal/server/global"
|
||||
"next-terminal/server/repository"
|
||||
|
||||
"github.com/labstack/gommon/log"
|
||||
"github.com/robfig/cron/v3"
|
||||
@ -42,8 +44,10 @@ func Run() error {
|
||||
if global.Config.ResetPassword != "" {
|
||||
return api.ResetPassword()
|
||||
}
|
||||
|
||||
api.SetupTicker()
|
||||
sessionRepo := repository.NewSessionRepository(db)
|
||||
propertyREpo := repository.NewPropertyRepository(db)
|
||||
ticker := task.NewTicker(sessionRepo, propertyREpo)
|
||||
ticker.SetupTicker()
|
||||
|
||||
if global.Config.Server.Cert != "" && global.Config.Server.Key != "" {
|
||||
return e.StartTLS(global.Config.Server.Addr, global.Config.Server.Cert, global.Config.Server.Key)
|
||||
|
@ -1,7 +1,7 @@
|
||||
package global
|
||||
|
||||
import (
|
||||
"next-terminal/server/config"
|
||||
"next-terminal/pkg/config"
|
||||
|
||||
"github.com/patrickmn/go-cache"
|
||||
"github.com/robfig/cron/v3"
|
@ -5,7 +5,7 @@ import (
|
||||
"sync"
|
||||
|
||||
"next-terminal/pkg/guacd"
|
||||
"next-terminal/server/term"
|
||||
"next-terminal/pkg/term"
|
||||
|
||||
"github.com/gorilla/websocket"
|
||||
)
|
@ -7,12 +7,12 @@ import (
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"next-terminal/pkg/constant"
|
||||
"next-terminal/pkg/global"
|
||||
"next-terminal/pkg/log"
|
||||
"next-terminal/server/constant"
|
||||
"next-terminal/server/global"
|
||||
"next-terminal/pkg/term"
|
||||
"next-terminal/server/model"
|
||||
"next-terminal/server/repository"
|
||||
"next-terminal/server/term"
|
||||
"next-terminal/server/utils"
|
||||
|
||||
"github.com/robfig/cron/v3"
|
@ -3,8 +3,8 @@ package service
|
||||
import (
|
||||
"net/smtp"
|
||||
|
||||
"next-terminal/pkg/constant"
|
||||
"next-terminal/pkg/log"
|
||||
"next-terminal/server/constant"
|
||||
"next-terminal/server/repository"
|
||||
|
||||
"github.com/jordan-wright/email"
|
@ -1,7 +1,7 @@
|
||||
package service
|
||||
|
||||
import (
|
||||
"next-terminal/server/constant"
|
||||
"next-terminal/pkg/constant"
|
||||
"next-terminal/server/model"
|
||||
"next-terminal/server/repository"
|
||||
"next-terminal/server/utils"
|
@ -1,8 +1,8 @@
|
||||
package service
|
||||
|
||||
import (
|
||||
"next-terminal/pkg/constant"
|
||||
"next-terminal/pkg/log"
|
||||
"next-terminal/server/constant"
|
||||
"next-terminal/server/model"
|
||||
"next-terminal/server/repository"
|
||||
"next-terminal/server/utils"
|
@ -1,25 +1,35 @@
|
||||
package api
|
||||
package task
|
||||
|
||||
import (
|
||||
"strconv"
|
||||
"time"
|
||||
|
||||
"next-terminal/pkg/constant"
|
||||
"next-terminal/pkg/log"
|
||||
"next-terminal/server/constant"
|
||||
"next-terminal/server/repository"
|
||||
)
|
||||
|
||||
func SetupTicker() {
|
||||
type Ticker struct {
|
||||
sessionRepository *repository.SessionRepository
|
||||
propertyRepository *repository.PropertyRepository
|
||||
}
|
||||
|
||||
func NewTicker(sessionRepository *repository.SessionRepository, propertyRepository *repository.PropertyRepository) *Ticker {
|
||||
return &Ticker{sessionRepository: sessionRepository, propertyRepository: propertyRepository}
|
||||
}
|
||||
|
||||
func (t *Ticker) SetupTicker() {
|
||||
|
||||
// 每隔一小时删除一次未使用的会话信息
|
||||
unUsedSessionTicker := time.NewTicker(time.Minute * 60)
|
||||
go func() {
|
||||
for range unUsedSessionTicker.C {
|
||||
sessions, _ := sessionRepository.FindByStatusIn([]string{constant.NoConnect, constant.Connecting})
|
||||
sessions, _ := t.sessionRepository.FindByStatusIn([]string{constant.NoConnect, constant.Connecting})
|
||||
if len(sessions) > 0 {
|
||||
now := time.Now()
|
||||
for i := range sessions {
|
||||
if now.Sub(sessions[i].ConnectedTime.Time) > time.Hour*1 {
|
||||
_ = sessionRepository.DeleteById(sessions[i].ID)
|
||||
_ = t.sessionRepository.DeleteById(sessions[i].ID)
|
||||
s := sessions[i].Username + "@" + sessions[i].IP + ":" + strconv.Itoa(sessions[i].Port)
|
||||
log.Infof("会话「%v」ID「%v」超过1小时未打开,已删除。", s, sessions[i].ID)
|
||||
}
|
||||
@ -32,7 +42,7 @@ func SetupTicker() {
|
||||
timeoutSessionTicker := time.NewTicker(time.Hour * 24)
|
||||
go func() {
|
||||
for range timeoutSessionTicker.C {
|
||||
property, err := propertyRepository.FindByName("session-saved-limit")
|
||||
property, err := t.propertyRepository.FindByName("session-saved-limit")
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
@ -43,7 +53,7 @@ func SetupTicker() {
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
sessions, err := sessionRepository.FindOutTimeSessions(limit)
|
||||
sessions, err := t.sessionRepository.FindOutTimeSessions(limit)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
@ -53,7 +63,7 @@ func SetupTicker() {
|
||||
for i := range sessions {
|
||||
sessionIds = append(sessionIds, sessions[i].ID)
|
||||
}
|
||||
err := sessionRepository.DeleteByIds(sessionIds)
|
||||
err := t.sessionRepository.DeleteByIds(sessionIds)
|
||||
if err != nil {
|
||||
log.Errorf("删除离线会话失败 %v", err)
|
||||
}
|
@ -4,9 +4,9 @@ import (
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"next-terminal/server/global"
|
||||
"next-terminal/pkg/global"
|
||||
"next-terminal/pkg/totp"
|
||||
"next-terminal/server/model"
|
||||
"next-terminal/server/totp"
|
||||
"next-terminal/server/utils"
|
||||
|
||||
"github.com/labstack/echo/v4"
|
||||
@ -40,6 +40,11 @@ type Authorization struct {
|
||||
User model.User
|
||||
}
|
||||
|
||||
//
|
||||
//type UserServer struct {
|
||||
// repository.UserRepository
|
||||
//}
|
||||
|
||||
func LoginEndpoint(c echo.Context) error {
|
||||
var loginAccount LoginAccount
|
||||
if err := c.Bind(&loginAccount); err != nil {
|
||||
|
@ -1,8 +1,8 @@
|
||||
package api
|
||||
|
||||
import (
|
||||
"next-terminal/server/constant"
|
||||
"next-terminal/server/global"
|
||||
"next-terminal/pkg/constant"
|
||||
"next-terminal/pkg/global"
|
||||
"next-terminal/server/model"
|
||||
|
||||
"github.com/labstack/echo/v4"
|
||||
|
@ -8,7 +8,7 @@ import (
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"next-terminal/server/constant"
|
||||
"next-terminal/pkg/constant"
|
||||
"next-terminal/server/model"
|
||||
"next-terminal/server/utils"
|
||||
|
||||
|
@ -5,7 +5,7 @@ import (
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"next-terminal/server/constant"
|
||||
"next-terminal/pkg/constant"
|
||||
"next-terminal/server/model"
|
||||
"next-terminal/server/utils"
|
||||
|
||||
|
@ -4,8 +4,8 @@ import (
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"next-terminal/pkg/global"
|
||||
"next-terminal/pkg/log"
|
||||
"next-terminal/server/global"
|
||||
|
||||
"github.com/labstack/echo/v4"
|
||||
)
|
||||
|
@ -7,8 +7,8 @@ import (
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"next-terminal/server/constant"
|
||||
"next-terminal/server/global"
|
||||
"next-terminal/pkg/constant"
|
||||
"next-terminal/pkg/global"
|
||||
"next-terminal/server/utils"
|
||||
|
||||
"github.com/labstack/echo/v4"
|
||||
|
@ -4,13 +4,14 @@ import (
|
||||
"github.com/labstack/echo/v4"
|
||||
)
|
||||
|
||||
//
|
||||
// todo 监控
|
||||
func MonitorEndpoint(c echo.Context) (err error) {
|
||||
//ws, err := UpGrader.Upgrade(c.Response().Writer, c.Request(), nil)
|
||||
//if err != nil {
|
||||
// log.Errorf("升级为WebSocket协议失败:%v", err.Error())
|
||||
// return err
|
||||
//}
|
||||
|
||||
return
|
||||
|
||||
}
|
||||
|
@ -1,7 +1,7 @@
|
||||
package api
|
||||
|
||||
import (
|
||||
"next-terminal/server/constant"
|
||||
"next-terminal/pkg/constant"
|
||||
"next-terminal/server/repository"
|
||||
|
||||
"github.com/labstack/echo/v4"
|
||||
|
@ -7,11 +7,11 @@ import (
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"next-terminal/pkg/global"
|
||||
"next-terminal/pkg/log"
|
||||
"next-terminal/server/global"
|
||||
"next-terminal/pkg/service"
|
||||
"next-terminal/server/model"
|
||||
"next-terminal/server/repository"
|
||||
"next-terminal/server/service"
|
||||
"next-terminal/server/utils"
|
||||
|
||||
"github.com/labstack/echo/v4"
|
||||
|
@ -4,7 +4,7 @@ import (
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"next-terminal/server/global"
|
||||
"next-terminal/pkg/global"
|
||||
"next-terminal/server/model"
|
||||
"next-terminal/server/utils"
|
||||
|
||||
|
@ -13,9 +13,9 @@ import (
|
||||
"strings"
|
||||
"sync"
|
||||
|
||||
"next-terminal/pkg/constant"
|
||||
"next-terminal/pkg/global"
|
||||
"next-terminal/pkg/log"
|
||||
"next-terminal/server/constant"
|
||||
"next-terminal/server/global"
|
||||
"next-terminal/server/model"
|
||||
"next-terminal/server/utils"
|
||||
|
||||
|
@ -7,12 +7,12 @@ import (
|
||||
"strconv"
|
||||
"time"
|
||||
|
||||
"next-terminal/pkg/constant"
|
||||
"next-terminal/pkg/global"
|
||||
"next-terminal/pkg/guacd"
|
||||
"next-terminal/pkg/log"
|
||||
"next-terminal/server/constant"
|
||||
"next-terminal/server/global"
|
||||
"next-terminal/pkg/term"
|
||||
"next-terminal/server/model"
|
||||
"next-terminal/server/term"
|
||||
"next-terminal/server/utils"
|
||||
|
||||
"github.com/gorilla/websocket"
|
||||
|
@ -5,10 +5,10 @@ import (
|
||||
"path"
|
||||
"strconv"
|
||||
|
||||
"next-terminal/pkg/constant"
|
||||
"next-terminal/pkg/global"
|
||||
"next-terminal/pkg/guacd"
|
||||
"next-terminal/pkg/log"
|
||||
"next-terminal/server/constant"
|
||||
"next-terminal/server/global"
|
||||
"next-terminal/server/model"
|
||||
|
||||
"github.com/gorilla/websocket"
|
||||
|
@ -4,8 +4,8 @@ import (
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"next-terminal/pkg/global"
|
||||
"next-terminal/pkg/log"
|
||||
"next-terminal/server/global"
|
||||
"next-terminal/server/model"
|
||||
"next-terminal/server/utils"
|
||||
|
||||
|
@ -4,8 +4,8 @@ import (
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"next-terminal/server/constant"
|
||||
"next-terminal/server/global"
|
||||
"next-terminal/pkg/constant"
|
||||
"next-terminal/pkg/global"
|
||||
"next-terminal/server/model"
|
||||
"next-terminal/server/utils"
|
||||
|
||||
|
@ -1,7 +1,7 @@
|
||||
package repository
|
||||
|
||||
import (
|
||||
"next-terminal/server/constant"
|
||||
"next-terminal/pkg/constant"
|
||||
"next-terminal/server/model"
|
||||
|
||||
"gorm.io/gorm"
|
||||
|
@ -1,7 +1,7 @@
|
||||
package repository
|
||||
|
||||
import (
|
||||
"next-terminal/server/constant"
|
||||
"next-terminal/pkg/constant"
|
||||
"next-terminal/server/model"
|
||||
|
||||
"gorm.io/gorm"
|
||||
|
@ -5,7 +5,7 @@ import (
|
||||
"path"
|
||||
"time"
|
||||
|
||||
"next-terminal/server/constant"
|
||||
"next-terminal/pkg/constant"
|
||||
"next-terminal/server/model"
|
||||
|
||||
"gorm.io/gorm"
|
||||
|
Loading…
Reference in New Issue
Block a user