utils

package
v1.0.38 Latest Latest
Warning

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

Go to latest
Published: Oct 20, 2026 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// OffHeapBufferMB is the minimum off-heap buffer (metaspace, thread stacks, direct buffers, OS overhead)
	OffHeapBufferMB = 384
	// HeadroomRatio is the 25-30% headroom multiplier (1.28 represents 28% headroom)
	HeadroomRatio = 1.28
)

Variables

View Source
var (
	ErrBlockedIP     = errors.New("connection blocked by SSRF guard")
	ErrInvalidScheme = errors.New("invalid URL scheme: must be http or https")
	ErrMissingHost   = errors.New("url is missing host")
)

Functions

func DeduplicateStrings

func DeduplicateStrings(strings []string) []string

func EnsureMemoryHeadroom

func EnsureMemoryHeadroom(maxHeapMB int, configuredContainerMB int) (int, int64)

EnsureMemoryHeadroom validates that a container memory limit provides the required headroom over maxHeapMB. Returns the safe container memory limit in MB and bytes.

func NewSafeHTTPClient

func NewSafeHTTPClient(timeout time.Duration, allowPrivate bool) *http.Client

NewSafeHTTPClient returns an http.Client equipped with SSRF guards at connection time, socket dialing, and redirect following.

func ParseMemoryMB

func ParseMemoryMB(memStr string) (int, error)

ParseMemoryMB parses memory string values (e.g. "4096M", "4G", "4096") into megabytes

func ValidateIP

func ValidateIP(ip net.IP, allowPrivate bool) error

ValidateIP checks whether an IP address belongs to denied ranges (loopback, link-local, private RFC1918)

func ValidateURL

func ValidateURL(rawURL string, allowPrivate bool) (*url.URL, error)

ValidateURL performs static and DNS resolution validation on a URL

func ValidateURLStatic

func ValidateURLStatic(rawURL string, allowPrivate bool) (*url.URL, error)

ValidateURLStatic validates a URL without performing DNS resolution. It enforces the scheme and, when the host is an IP literal, the address policy. Use it where a DNS lookup must not happen (e.g. saving configuration); ValidateURL remains the resolving variant for actual outbound requests.

Types

type MemoryAllocation

type MemoryAllocation struct {
	InitMemoryMB        int
	MaxMemoryMB         int
	ContainerLimitMB    int
	InitMemoryStr       string
	MaxMemoryStr        string
	ContainerLimitBytes int64
}

MemoryAllocation holds calculated JVM and container memory limits to prevent cgroup OOM kills (exit 137)

func CalculateMemoryAllocation

func CalculateMemoryAllocation(allocatedRAMMB int) MemoryAllocation

CalculateMemoryAllocation calculates dynamic -Xms and -Xmx from total allocated RAM and guarantees container memory limit exceeds JVM -Xmx by 25-30% plus 384MB off-heap buffer.

Jump to

Keyboard shortcuts

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