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