utils

package
v0.15.1 Latest Latest
Warning

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

Go to latest
Published: Feb 27, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package utils provides helper functions for working with files, directories and strings that are shared across the proxsave codebase.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AbsPath

func AbsPath(path string) (string, error)

AbsPath returns the absolute path of a file.

func ComputeSHA256

func ComputeSHA256(filePath string) (string, error)

ComputeSHA256 computes the SHA256 checksum of a file.

func DirExists

func DirExists(path string) bool

DirExists checks whether a directory exists.

func EnsureDir

func EnsureDir(path string) error

EnsureDir creates a directory if it doesn't exist.

func FileExists

func FileExists(path string) bool

FileExists checks whether a file exists.

func FindClosingQuoteIndex added in v0.13.2

func FindClosingQuoteIndex(s string, quote byte) int

FindClosingQuoteIndex returns the index of the closing quote in s, honoring backslash escapes. Assumes s[0] is the opening quote.

func FindInlineCommentIndex added in v0.13.2

func FindInlineCommentIndex(line string) int

FindInlineCommentIndex returns the index of a # that starts an inline comment. A # inside quotes or escaped with a backslash is ignored.

func FormatBytes

func FormatBytes(bytes int64) string

FormatBytes converts bytes to a human-readable format (KB, MB, GB, etc.).

func GenerateRandomString

func GenerateRandomString(length int) string

GenerateRandomString generates a random string of the specified length

func GetFileSize

func GetFileSize(filePath string) (int64, error)

GetFileSize returns the file size in bytes.

func IsAbsPath

func IsAbsPath(path string) bool

IsAbsPath checks whether a path is absolute.

func IsComment

func IsComment(line string) bool

IsComment checks whether a line is a comment (starts with #).

func ParseBool

func ParseBool(s string) bool

ParseBool converts a string to a boolean (supports multiple formats).

func SetEnvValue added in v0.13.2

func SetEnvValue(template, key, value string) string

SetEnvValue sets or updates a KEY=VALUE line in a template, preserving indentation and comments.

func SplitKeyValue

func SplitKeyValue(line string) (string, string, bool)

SplitKeyValue splits a "key=value" string into key and value. Supports inline comments too: KEY="value" # comment

func TrimQuotes

func TrimQuotes(s string) string

TrimQuotes removes surrounding quotes from a string.

Types

This section is empty.

Jump to

Keyboard shortcuts

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