feat: implement GoongController to proxy requests with automatic API key injection
All checks were successful
Build and Release / release (push) Successful in 1m32s

This commit is contained in:
2026-05-18 19:39:02 +07:00
parent 65f73a70f1
commit ba5ac2df7d

View File

@@ -2,6 +2,7 @@ package controllers
import ( import (
"history-api/internal/services" "history-api/internal/services"
"net/url"
"strings" "strings"
"github.com/gofiber/fiber/v3" "github.com/gofiber/fiber/v3"
@@ -41,6 +42,9 @@ func (ctrl *goongController) Proxy(c fiber.Ctx) error {
} }
targetURL := path targetURL := path
if decodedURL, err := url.PathUnescape(targetURL); err == nil {
targetURL = decodedURL
}
if strings.HasPrefix(targetURL, "https:/") && !strings.HasPrefix(targetURL, "https://") { if strings.HasPrefix(targetURL, "https:/") && !strings.HasPrefix(targetURL, "https://") {
targetURL = strings.Replace(targetURL, "https:/", "https://", 1) targetURL = strings.Replace(targetURL, "https:/", "https://", 1)
@@ -49,8 +53,12 @@ func (ctrl *goongController) Proxy(c fiber.Ctx) error {
} }
if len(c.Request().URI().QueryString()) > 0 { if len(c.Request().URI().QueryString()) > 0 {
if strings.Contains(targetURL, "?") {
targetURL += "&" + string(c.Request().URI().QueryString())
} else {
targetURL += "?" + string(c.Request().URI().QueryString()) targetURL += "?" + string(c.Request().URI().QueryString())
} }
}
headers := make(map[string]string) headers := make(map[string]string)
for k, v := range c.GetReqHeaders() { for k, v := range c.GetReqHeaders() {