优化代码结构

This commit is contained in:
2025-05-12 15:13:48 +08:00
parent 8bab6291b1
commit 536f36ae02
11 changed files with 45 additions and 182 deletions

View File

@@ -4,7 +4,7 @@ import (
"log/slog"
"net"
"proxy-server/server/fwd/core"
"proxy-server/server/pkg/models"
"proxy-server/server/fwd/repo"
"proxy-server/server/pkg/orm"
"strconv"
"time"
@@ -38,8 +38,8 @@ func CheckIp(conn net.Conn, proto Protocol) (*core.AuthContext, error) {
// 查询权限记录
slog.Debug("用户 " + remoteHost + " 请求连接到 " + _localPort)
var channels []models.Channel
err = orm.DB.Find(&channels, &models.Channel{
var channels []repo.Channel
err = orm.DB.Find(&channels, &repo.Channel{
AuthIp: true,
UserAddr: remoteHost,
NodePort: localPort,
@@ -84,8 +84,8 @@ func CheckPass(conn net.Conn, proto Protocol, username, password string) (*core.
}
// 查询权限记录
var channel models.Channel
err = orm.DB.Take(&channel, &models.Channel{
var channel repo.Channel
err = orm.DB.Take(&channel, &repo.Channel{
AuthPass: true,
Username: username,
NodePort: localPort,

View File

@@ -9,8 +9,8 @@ import (
"proxy-server/server/fwd/core"
"proxy-server/server/fwd/dispatcher"
"proxy-server/server/fwd/metrics"
"proxy-server/server/fwd/repo"
"proxy-server/server/pkg/env"
"proxy-server/server/pkg/models"
"proxy-server/server/pkg/orm"
"strconv"
"strings"
@@ -93,8 +93,8 @@ func (s *Service) processCtrlConn(conn net.Conn) error {
}
// 检查客户端
var node models.Node
err = orm.DB.Take(&node, &models.Node{
var node repo.Node
err = orm.DB.Take(&node, &repo.Node{
Name: name,
}).Error
if err != nil {

View File

@@ -1,4 +1,4 @@
package models
package repo
import (
"time"

View File

@@ -1,4 +1,4 @@
package models
package repo
import "gorm.io/gorm"

View File

@@ -1,9 +0,0 @@
package models
import "gorm.io/gorm"
type UserIp struct {
gorm.Model
UserId uint
IpAddress string
}

View File

@@ -1,14 +0,0 @@
package models
import "gorm.io/gorm"
type User struct {
gorm.Model
Password string
Username string
Email string
Phone string
Name string
Channels []Channel `gorm:"foreignKey:UserId"`
}