refactor: restructure project architecture
This commit is contained in:
@@ -10,16 +10,16 @@ import (
|
||||
"strconv"
|
||||
"sync"
|
||||
"time"
|
||||
"tunnel_pls/internal/config"
|
||||
"tunnel_pls/session/slug"
|
||||
"tunnel_pls/types"
|
||||
"tunnel_pls/utils"
|
||||
|
||||
"golang.org/x/crypto/ssh"
|
||||
)
|
||||
|
||||
var bufferPool = sync.Pool{
|
||||
New: func() interface{} {
|
||||
bufSize := utils.GetBufferSize()
|
||||
bufSize := config.GetBufferSize()
|
||||
return make([]byte, bufSize)
|
||||
},
|
||||
}
|
||||
|
||||
@@ -7,10 +7,9 @@ import (
|
||||
"log"
|
||||
"net"
|
||||
portUtil "tunnel_pls/internal/port"
|
||||
"tunnel_pls/internal/random"
|
||||
"tunnel_pls/types"
|
||||
|
||||
"tunnel_pls/utils"
|
||||
|
||||
"golang.org/x/crypto/ssh"
|
||||
)
|
||||
|
||||
@@ -276,7 +275,7 @@ func generateUniqueSlug() string {
|
||||
maxAttempts := 5
|
||||
|
||||
for i := 0; i < maxAttempts; i++ {
|
||||
slug := utils.GenerateRandomString(20)
|
||||
slug := random.GenerateRandomString(20)
|
||||
|
||||
clientsMutex.RLock()
|
||||
_, exists := Clients[slug]
|
||||
|
||||
@@ -6,9 +6,10 @@ import (
|
||||
"log"
|
||||
"strings"
|
||||
"time"
|
||||
"tunnel_pls/internal/config"
|
||||
"tunnel_pls/internal/random"
|
||||
"tunnel_pls/session/slug"
|
||||
"tunnel_pls/types"
|
||||
"tunnel_pls/utils"
|
||||
|
||||
"github.com/charmbracelet/bubbles/help"
|
||||
"github.com/charmbracelet/bubbles/key"
|
||||
@@ -722,9 +723,9 @@ func (m model) View() string {
|
||||
func (i *Interaction) Start() {
|
||||
lipgloss.SetColorProfile(termenv.TrueColor)
|
||||
|
||||
domain := utils.Getenv("DOMAIN", "localhost")
|
||||
domain := config.Getenv("DOMAIN", "localhost")
|
||||
protocol := "http"
|
||||
if utils.Getenv("TLS_ENABLED", "false") == "true" {
|
||||
if config.Getenv("TLS_ENABLED", "false") == "true" {
|
||||
protocol = "https"
|
||||
}
|
||||
|
||||
@@ -811,7 +812,7 @@ func buildURL(protocol, subdomain, domain string) string {
|
||||
}
|
||||
|
||||
func generateRandomSubdomain() string {
|
||||
return utils.GenerateRandomString(20)
|
||||
return random.GenerateRandomString(20)
|
||||
}
|
||||
|
||||
func isValidSlug(slug string) bool {
|
||||
|
||||
@@ -4,11 +4,11 @@ import (
|
||||
"log"
|
||||
"sync"
|
||||
"time"
|
||||
"tunnel_pls/internal/config"
|
||||
"tunnel_pls/session/forwarder"
|
||||
"tunnel_pls/session/interaction"
|
||||
"tunnel_pls/session/lifecycle"
|
||||
"tunnel_pls/session/slug"
|
||||
"tunnel_pls/utils"
|
||||
|
||||
"golang.org/x/crypto/ssh"
|
||||
)
|
||||
@@ -79,7 +79,7 @@ func New(conn *ssh.ServerConn, forwardingReq <-chan *ssh.Request, sshChan <-chan
|
||||
|
||||
tcpipReq := session.waitForTCPIPForward(forwardingReq)
|
||||
if tcpipReq == nil {
|
||||
log.Printf("Port forwarding request not received. Ensure you ran the correct command with -R flag. Example: ssh %s -p %s -R 80:localhost:3000", utils.Getenv("DOMAIN", "localhost"), utils.Getenv("PORT", "2200"))
|
||||
log.Printf("Port forwarding request not received. Ensure you ran the correct command with -R flag. Example: ssh %s -p %s -R 80:localhost:3000", config.Getenv("DOMAIN", "localhost"), config.Getenv("PORT", "2200"))
|
||||
if err := session.lifecycle.Close(); err != nil {
|
||||
log.Printf("failed to close session: %v", err)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user