feat: add pprof for debuging
All checks were successful
Docker Build and Push / build-and-push (push) Successful in 3m51s

This commit is contained in:
2025-12-18 18:30:49 +07:00
parent 6451304ed7
commit 7bc5a01ba7
9 changed files with 150 additions and 23 deletions

24
main.go
View File

@@ -1,7 +1,10 @@
package main
import (
"fmt"
"log"
"net/http"
_ "net/http/pprof"
"os"
"tunnel_pls/server"
"tunnel_pls/utils"
@@ -12,13 +15,30 @@ import (
func main() {
log.SetOutput(os.Stdout)
log.SetFlags(log.LstdFlags | log.Lshortfile)
pprofEnabled := utils.Getenv("PPROF_ENABLED", "false")
if pprofEnabled == "true" {
pprofPort := utils.Getenv("PPROF_PORT", "6060")
go func() {
pprofAddr := fmt.Sprintf("localhost:%s", pprofPort)
log.Printf("Starting pprof server on http://%s/debug/pprof/", pprofAddr)
if err := http.ListenAndServe(pprofAddr, nil); err != nil {
log.Printf("pprof server error: %v", err)
}
}()
}
sshConfig := &ssh.ServerConfig{
NoClientAuth: true,
ServerVersion: "SSH-2.0-TunnlPls-1.0",
}
privateBytes, err := os.ReadFile(utils.Getenv("ssh_private_key"))
sshKeyPath := utils.Getenv("SSH_PRIVATE_KEY", "certs/id_rsa")
if err := utils.GenerateSSHKeyIfNotExist(sshKeyPath); err != nil {
log.Fatalf("Failed to generate SSH key: %s", err)
}
privateBytes, err := os.ReadFile(sshKeyPath)
if err != nil {
log.Fatalf("Failed to load private key: %s", err)
}