From 102a48fa12fc3a392f3839c78b49c80f3ad5946a Mon Sep 17 00:00:00 2001 From: cangui Date: Mon, 18 Aug 2025 18:59:39 +0200 Subject: [PATCH] up --- main.go | 45 +++++++++++++++++++++++++-------------------- 1 file changed, 25 insertions(+), 20 deletions(-) diff --git a/main.go b/main.go index 47c35a3..4598ca3 100644 --- a/main.go +++ b/main.go @@ -253,25 +253,30 @@ func startHTTP() { _ = app.Run(":8080") } -func main() { - // SFTP sur 2222 (root = ./upload) - go startSFTPServer(SFTPBaseDir) +// ---------- Main ---------- - // HTTP normal - startHTTP() +func main() { + + go startSFTPServer(SFTPBaseDir) + + + // Serveur HTTP Gin + bd := db.InitDB() + app := gin.Default() + + api := app.Group("/api/v1") + routes.AddRoutes(api, bd) + utils.CreateDefaultFolder(bd) + + app.Static("/static", "./web") + app.NoRoute(func(c *gin.Context) { + if strings.HasPrefix(c.Request.URL.Path, "/api/") { + c.JSON(404, gin.H{"error": "Not found"}) + return + } + c.File("./web/index.html") + }) + + log.Println("[HTTP] Serveur Gin sur http://localhost:8080") + app.Run(":8080") } -func loadOrCreateRSAHostKey(path string) (ssh.Signer, error) { - if _, err := os.Stat(path); err == nil { - b, err := os.ReadFile(path) - if err != nil { return nil, err } - return ssh.ParsePrivateKey(b) - } - // Génère une clé RSA 2048 - priv, err := rsa.GenerateKey(rand.Reader, 2048) - if err != nil { return nil, err } - // Encode en PEM "RSA PRIVATE KEY" (PKCS#1) - pkcs1 := x509.MarshalPKCS1PrivateKey(priv) - pemBytes := pem.EncodeToMemory(&pem.Block{Type: "RSA PRIVATE KEY", Bytes: pkcs1}) - if err := os.WriteFile(path, pemBytes, 0o600); err != nil { return nil, err } - return ssh.ParsePrivateKey(pemBytes) -} \ No newline at end of file