utils

package
v0.0.21 Latest Latest
Warning

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

Go to latest
Published: Jun 6, 2025 License: MIT Imports: 26 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CleanAndValidateHost

func CleanAndValidateHost(host string) (string, error)

CleanAndValidateHost takes a host string and returns a cleaned version with protocol removed and ensures it's a valid domain. Returns an error if the host is invalid.

func ContainsExactlyOneInterpolationMarker

func ContainsExactlyOneInterpolationMarker(s string) bool

Makes sure a string contains one interpolation marker, ${} , allow escaping to ignore

func DecodePrivateKey

func DecodePrivateKey(keyData string) (*rsa.PrivateKey, error)

func EnsureSuffix

func EnsureSuffix(s, suffix string) string

func ExtractRepoName

func ExtractRepoName(gitURL string) (string, error)

func FileExists

func FileExists(filename string) bool

Returns true if the file exists

func FindFiles

func FindFiles(rootDir string, pattern string) ([]string, error)

FindFiles recursively searches for files in rootDir that match the provided pattern. Pattern uses the same syntax as filepath.Match (e.g., "*.go", "config.*").

func FindFilesWithExclusions

func FindFilesWithExclusions(rootDir string, pattern string, excludeDirs []string) ([]string, error)

FindFilesWithExclusions is like FindFiles but allows excluding certain directories or patterns

func FromPtr

func FromPtr[T any](p *T) T

func GenerateGithubJWT

func GenerateGithubJWT(appID int64, privateKey *rsa.PrivateKey) (string, error)

Generate JWT to authenticate with github APIs

func GenerateRandomSimpleID

func GenerateRandomSimpleID(length int) (string, error)

func GenerateSecurePassword

func GenerateSecurePassword(length int, simple bool) (string, error)

GenerateSecurePassword creates a password with the required constraints

func GenerateSlug

func GenerateSlug(displayName string) (string, error)

func GenerateSubdomain

func GenerateSubdomain(name, externalURL string) (string, error)

Generate a default subdomain

func GetExposedPortsFromRegistry

func GetExposedPortsFromRegistry(imageName string) ([]string, error)

GetexportedPortsFromRegistry detects exposed ports from a docker manifest, in 8080/tcp format

func GetIPAddress

func GetIPAddress(r *http.Request) string

func InferOperatorPVCMountPath

func InferOperatorPVCMountPath(databaseType string) *string

InferOperatorPVCMountPath infers the mount path for a PVC based on the operator type (database)

func IsTextFile

func IsTextFile(path string) bool

IsTextFile checks if a file appears to be a text file rather than binary

func IsValidGlobPattern

func IsValidGlobPattern(pattern string) bool

IsValidGlobPattern checks if a string is a valid glob pattern

func IsValidUnixPath

func IsValidUnixPath(path string) bool

IsValidUnixPath checks if the given path is a valid Unix-style path. A valid Unix path: - Starts with a forward slash (/) - Contains only forward slashes as separators - Does not contain Windows-style backslashes - Does not contain invalid characters

func JoinURLPaths

func JoinURLPaths(baseURL string, paths ...string) (string, error)

func MatchesGlobPattern

func MatchesGlobPattern(value, pattern string) bool

MatchesGlobPattern checks if a value matches a glob pattern

func ReadFile

func ReadFile(path string) (string, error)

ReadFile reads the content of a file at the given path and returns it as a string. It handles potential errors and has a configurable maximum file size.

func ReadFileWithLimit

func ReadFileWithLimit(path string, maxSizeBytes int64) (string, error)

ReadFileWithLimit reads file content with a specified size limit

func SafeReadFile

func SafeReadFile(path string) (string, bool)

SafeReadFile attempts to read a file with proper error handling and defaults

func ToPtr

func ToPtr[T any](v T) *T

func ValidateAndExtractDomain

func ValidateAndExtractDomain(urlStr string) (string, error)

ValidateAndExtractDomain takes a URL string and: 1. Validates if it's a proper URL (must start with http:// or https://) 2. Extracts the domain name 3. Converts special characters to hyphens Returns the transformed domain and an error if invalid

func ValidateCronExpression

func ValidateCronExpression(cron string) error

ValidateCronExpression validates a cron expression string. It checks if the expression follows the standard cron format: minute hour day month weekday Returns an error if the expression is invalid, nil if valid.

func ValidateStorageQuantity

func ValidateStorageQuantity(s string) (resource.Quantity, error)

validateStorageQuantity returns the parsed Quantity or an error if the string isn’t a whole-byte storage unit.

func ValidateStorageQuantityGB

func ValidateStorageQuantityGB(sizeGB float64) (resource.Quantity, error)

validateStorageQuantity returns the parsed Quantity or an error if the string isn’t a whole-byte storage unit.

Types

type DNSChecker

type DNSChecker struct {
	// contains filtered or unexported fields
}

DNSChecker provides methods to check DNS and Cloudflare proxy status

func NewDNSChecker

func NewDNSChecker() *DNSChecker

NewDNSChecker creates a new DNSChecker instance with default settings

func (*DNSChecker) IsPointingToIP

func (self *DNSChecker) IsPointingToIP(domain string, expectedIP string) (bool, error)

IsPointingToIP checks if a domain is pointing to a specific IP address

func (*DNSChecker) IsUsingCloudflareProxy

func (self *DNSChecker) IsUsingCloudflareProxy(domain string) (bool, error)

IsUsingCloudflareProxy checks if a domain is using Cloudflare proxy

Jump to

Keyboard shortcuts

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