refactor: explicit initialization and dependency injection

- Replace init() with config.Load() function when loading env variables
- Inject portRegistry into session, server, and lifecycle structs
- Inject sessionRegistry directly into interaction and lifecycle
- Remove SetSessionRegistry function and global port variables
- Pass ssh.Conn directly to forwarder constructor instead of lifecycle interface
- Pass user and closeFunc callback to interaction constructor instead of lifecycle interface
- Eliminate circular dependencies between lifecycle, forwarder, and interaction
- Remove setter methods (SetLifecycle) from forwarder and interaction interfaces
This commit is contained in:
2026-01-18 20:42:10 +07:00
parent 9be0328e24
commit cdfe81baed
11 changed files with 105 additions and 131 deletions
+3 -5
View File
@@ -1,19 +1,17 @@
package config
import (
"log"
"os"
"strconv"
"github.com/joho/godotenv"
)
func init() {
func Load() error {
if _, err := os.Stat(".env"); err == nil {
if err := godotenv.Load(".env"); err != nil {
log.Printf("Warning: Failed to load .env file: %s", err)
}
return godotenv.Load(".env")
}
return nil
}
func Getenv(key, defaultValue string) string {