new proxy implementation with Gin framework

- Created a new proxy structure under NewProxy/ using the Gin web framework.
- Added main entry point (main.go) to register and run routes.
- Implemented new route handlers for:
 > Status — monitors active downloads and total data transferred.
 > Forward — handles proxy forwarding logic.
 > Builds — manages build-related requests.
This commit is contained in:
Andrei Alexandru
2025-10-20 04:14:45 +03:00
parent e9f9211e39
commit da38f036ed
8 changed files with 310 additions and 0 deletions

50
NewProxy/routes/status.go Normal file
View File

@@ -0,0 +1,50 @@
package routes
import (
"github.com/gin-gonic/gin"
"newproxy/utils"
"net/http"
"sync"
"time"
"fmt"
)
var (
activeDownloads = make(map[string]float64)
totalDownloadedBytes int64
mu sync.Mutex
)
func RegisterStatusRoute(r *gin.Engine) {
r.GET("/status", statusHandler)
}
func statusHandler(c *gin.Context) {
mu.Lock()
defer mu.Unlock()
timeout := 10.0
currentTime := float64(time.Now().Unix())
filtered := make(map[string]float64)
for ip, ts := range activeDownloads {
if currentTime-ts < timeout {
filtered[ip] = ts
}
}
activeDownloads = filtered
var totalDownloaded string
if totalDownloadedBytes >= 1_000_000_000 {
totalDownloaded = fmt.Sprintf("%.2f GB", float64(totalDownloadedBytes)/1_000_000_000)
} else {
totalDownloaded = fmt.Sprintf("%.2f MB", float64(totalDownloadedBytes)/1_000_000)
}
c.JSON(http.StatusOK, gin.H{
"latest_release_version": utils.LatestRelease.ReleaseVersion,
"proxy_version": "1.6.2",
"active_downloads": len(activeDownloads),
"total_downloaded": totalDownloaded,
})
}