Documentation
¶
Index ¶
- func ConstructURL(domain, path string) string
- func ExtractPathFromURL(fullURL string) string
- func GetClientIP(r *http.Request) string
- func IsSignificantRedirect(originalURL, redirectURL string) bool
- func NormaliseDomain(domain string) string
- func NormaliseURL(rawURL string) string
- func SanitiseForJSON(s string) string
- func ValidateDomain(domain string) error
- type RequestMeta
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ConstructURL ¶
ConstructURL builds a proper URL from domain and path components
func ExtractPathFromURL ¶
ExtractPathFromURL extracts just the path component from a full URL
func GetClientIP ¶
GetClientIP extracts the client IP address from a request, respecting proxy headers (X-Forwarded-For, X-Real-IP).
func IsSignificantRedirect ¶
IsSignificantRedirect checks if a redirect URL is meaningfully different from the original. Only the host and path are compared; query parameters and fragments are ignored. Returns false for trivial redirects like:
- HTTP to HTTPS on same domain/path
- www to non-www (or vice versa) on same path
- Trailing slash differences
- Default port differences (e.g., :443 for HTTPS, :80 for HTTP)
Returns true for redirects to different domains or different paths.
func NormaliseDomain ¶
NormaliseDomain removes http/https prefix and www. from domain
func NormaliseURL ¶
NormaliseURL ensures a URL has proper https:// scheme and validates format
func SanitiseForJSON ¶
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 ¶
ValidateDomain checks if a domain string is a valid domain format. Uses golang.org/x/net/publicsuffix for robust validation against the Public Suffix List. Returns an error describing why the domain is invalid, or nil if valid.
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.