Files
latosa-escrima/backend/utils/get_url.go
2025-02-11 11:22:43 +01:00

28 lines
466 B
Go

package utils
import (
"fmt"
"net/http"
"os"
)
func GetURL(r *http.Request) string {
scheme := "http"
if r.TLS != nil { // Check if the request is over HTTPS
scheme = "https"
}
// Extract the host
host := r.Host
// Get the full request URI (path + query string)
fullPath := r.URL.Path
if os.Getenv("ENVIRONMENT") != "DEVELOPMENT" {
fullPath += "/api/"
}
// Build the full request URL
return fmt.Sprintf("%s://%s%s", scheme, host, fullPath)
}