util

package
v0.33.14 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 29, 2026 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ConstructURL

func ConstructURL(domain, path string) string

func ExtractPathFromURL

func ExtractPathFromURL(fullURL string) string

func FDPressure added in v0.31.4

func FDPressure() float64

Returns 0 (fail-open) on error.

func FDPressureFrom added in v0.31.4

func FDPressureFrom(current, limit int) float64

Returns 0 (fail-open) when limit <= 0.

func FDUsage added in v0.31.4

func FDUsage() (current, limit int, err error)

FDUsage is Linux-only (/proc/self); returns (0, 0, err) elsewhere.

func GetClientIP

func GetClientIP(r *http.Request) string

GetClientIP extracts the client IP address from a request, respecting proxy headers (X-Forwarded-For, X-Real-IP).

func IsSignificantRedirect

func IsSignificantRedirect(originalURL, redirectURL string) bool

IsSignificantRedirect: ignores HTTP↔HTTPS, www↔non-www, default-port and trailing-slash variants — only host/path differences count.

func NormaliseDomain

func NormaliseDomain(domain string) string

func NormaliseURL

func NormaliseURL(rawURL string) string

func SanitiseForJSON

func SanitiseForJSON(s string) string

SanitiseForJSON strips control characters (tabs, newlines, etc.) from a string so it can be safely embedded in a JSON value via a Go template. Supabase's email templates render {{ .Data.* }} without JSON-escaping, so any control character in user_metadata breaks the Loops payload.

func ValidateDomain

func ValidateDomain(domain string) error

Types

type RequestMeta

type RequestMeta struct {
	IP        string
	UserAgent string
	Browser   string
	OS        string
	Device    string // e.g. "Chrome on macOS"
	City      string // From Cloudflare cf-ipcity header
	Region    string // From Cloudflare cf-region header
	Country   string // From Cloudflare cf-ipcountry header (ISO code)
	Timezone  string // From Cloudflare cf-timezone header
	Location  string // Formatted e.g. "Melbourne, Victoria, Australia"
	Timestamp time.Time
}

RequestMeta contains metadata extracted from an HTTP request. Useful for audit logging and contextual email content.

func ExtractRequestMeta

func ExtractRequestMeta(r *http.Request) *RequestMeta

ExtractRequestMeta extracts client metadata from an HTTP request. Location fields (City, Region, Country, Timezone) require the Cloudflare "Add visitor location headers" managed transform to be enabled.

func (*RequestMeta) FormattedTimestamp

func (m *RequestMeta) FormattedTimestamp() string

FormattedTimestamp returns the timestamp in a human-readable format.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL