refactor: restructure project architecture
renovate / renovate (push) Successful in 45s
Docker Build and Push / build-and-push-branches (push) Successful in 5m54s
Docker Build and Push / build-and-push-tags (push) Successful in 6m21s

This commit is contained in:
2025-12-31 15:49:37 +07:00
parent 878664e0ac
commit acd02aadd3
13 changed files with 89 additions and 77 deletions
+4 -4
View File
@@ -11,8 +11,8 @@ import (
"regexp"
"strings"
"time"
"tunnel_pls/internal/config"
"tunnel_pls/session"
"tunnel_pls/utils"
"golang.org/x/crypto/ssh"
)
@@ -231,12 +231,12 @@ func (cw *customWriter) AddInteraction(interaction Interaction) {
var redirectTLS = false
func NewHTTPServer() error {
httpPort := utils.Getenv("HTTP_PORT", "8080")
httpPort := config.Getenv("HTTP_PORT", "8080")
listener, err := net.Listen("tcp", ":"+httpPort)
if err != nil {
return errors.New("Error listening: " + err.Error())
}
if utils.Getenv("TLS_ENABLED", "false") == "true" && utils.Getenv("TLS_REDIRECT", "false") == "true" {
if config.Getenv("TLS_ENABLED", "false") == "true" && config.Getenv("TLS_REDIRECT", "false") == "true" {
redirectTLS = true
}
go func() {
@@ -288,7 +288,7 @@ func Handler(conn net.Conn) {
if redirectTLS {
_, err = conn.Write([]byte("HTTP/1.1 301 Moved Permanently\r\n" +
fmt.Sprintf("Location: https://%s.%s/\r\n", slug, utils.Getenv("DOMAIN", "localhost")) +
fmt.Sprintf("Location: https://%s.%s/\r\n", slug, config.Getenv("DOMAIN", "localhost")) +
"Content-Length: 0\r\n" +
"Connection: close\r\n" +
"\r\n"))
+3 -3
View File
@@ -8,13 +8,13 @@ import (
"log"
"net"
"strings"
"tunnel_pls/internal/config"
"tunnel_pls/session"
"tunnel_pls/utils"
)
func NewHTTPSServer() error {
domain := utils.Getenv("DOMAIN", "localhost")
httpsPort := utils.Getenv("HTTPS_PORT", "8443")
domain := config.Getenv("DOMAIN", "localhost")
httpsPort := config.Getenv("HTTPS_PORT", "8443")
tlsConfig, err := NewTLSConfig(domain)
if err != nil {
+5 -5
View File
@@ -5,7 +5,7 @@ import (
"log"
"net"
"net/http"
"tunnel_pls/utils"
"tunnel_pls/internal/config"
"golang.org/x/crypto/ssh"
)
@@ -28,13 +28,13 @@ func (s *Server) GetHttpServer() *http.Server {
return s.httpServer
}
func NewServer(config *ssh.ServerConfig) *Server {
listener, err := net.Listen("tcp", fmt.Sprintf(":%s", utils.Getenv("PORT", "2200")))
func NewServer(sshConfig *ssh.ServerConfig) *Server {
listener, err := net.Listen("tcp", fmt.Sprintf(":%s", config.Getenv("PORT", "2200")))
if err != nil {
log.Fatalf("failed to listen on port 2200: %v", err)
return nil
}
if utils.Getenv("TLS_ENABLED", "false") == "true" {
if config.Getenv("TLS_ENABLED", "false") == "true" {
err = NewHTTPSServer()
if err != nil {
log.Fatalf("failed to start https server: %v", err)
@@ -46,7 +46,7 @@ func NewServer(config *ssh.ServerConfig) *Server {
}
return &Server{
conn: &listener,
config: config,
config: sshConfig,
}
}
+5 -5
View File
@@ -10,7 +10,7 @@ import (
"os"
"sync"
"time"
"tunnel_pls/utils"
"tunnel_pls/internal/config"
"github.com/caddyserver/certmagic"
"github.com/libdns/cloudflare"
@@ -92,7 +92,7 @@ func NewTLSConfig(domain string) (*tls.Config, error) {
}
func isACMEConfigComplete() bool {
cfAPIToken := utils.Getenv("CF_API_TOKEN", "")
cfAPIToken := config.Getenv("CF_API_TOKEN", "")
return cfAPIToken != ""
}
@@ -241,9 +241,9 @@ func (tm *tlsManager) initCertMagic() error {
return fmt.Errorf("failed to create cert storage directory: %w", err)
}
acmeEmail := utils.Getenv("ACME_EMAIL", "admin@"+tm.domain)
cfAPIToken := utils.Getenv("CF_API_TOKEN", "")
acmeStaging := utils.Getenv("ACME_STAGING", "false") == "true"
acmeEmail := config.Getenv("ACME_EMAIL", "admin@"+tm.domain)
cfAPIToken := config.Getenv("CF_API_TOKEN", "")
acmeStaging := config.Getenv("ACME_STAGING", "false") == "true"
if cfAPIToken == "" {
return fmt.Errorf("CF_API_TOKEN environment variable is required for automatic certificate generation")