common

package
v1.0.33 Latest Latest
Warning

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

Go to latest
Published: Dec 15, 2025 License: Apache-2.0 Imports: 19 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var AppMode bool
View Source
var (
	// GentleIO controls whether to use gentle I/O for CRC calculation
	// When true, uses fadviseDontNeed and throttling to reduce cache pollution
	GentleIO = false
)

Functions

func ByteSize

func ByteSize(bytes uint64) string

func Chmod

func Chmod(path string, mod os.FileMode)

Chmod changes mod of a path

func CreateFile

func CreateFile(path string, size int64)

CreateFile creates an empty file with given length (if size > 0)

func CreateFolder

func CreateFolder(path string)

CreateFolder creates folder on local drive

func DoWithRetry added in v1.0.28

func DoWithRetry(operation func() error, config RetryConfig) error

DoWithRetry executes a function with retry logic If all retries fail, it returns the last error encountered

func DoWithRetrySimple added in v1.0.28

func DoWithRetrySimple(operation func() error) error

DoWithRetrySimple is a simplified version using default retry configuration

func Elapsed

func Elapsed(s string, start time.Time)

Elapsed gets time elapsed

func Exit

func Exit()

Exit exits the program with non-zero status code

func FadviseWriteDontNeed added in v1.0.33

func FadviseWriteDontNeed(file *os.File, offset, length int64)

FadviseWriteDontNeed tells kernel to write back and drop cache for written data

func FadviseWriteSequential added in v1.0.33

func FadviseWriteSequential(file *os.File)

FadviseWriteSequential hints kernel for sequential write pattern

func Finish

func Finish()

Finish exits the program with zero status code

func FromByteSize

func FromByteSize(s string) string

FromByteSize converts size string in bytes into uinit, e.g., 1024 into 1K

func GenTempFileName

func GenTempFileName(parts ...string) string

GenTempFileName generate /tmp/%x files where %x is md5 value of all parts concate together

func GetDstPath

func GetDstPath(srcPrefix, srcPath, dstPrefix string) string

GetDstPath gets the destination path

func GetFileCRC32C

func GetFileCRC32C(path string) uint32

GetFileCRC32C gets the crc32c of a file

func GetFileMD5

func GetFileMD5(path string) []byte

GetFileMD5 gets the md5 of a file

func GetFileModificationTime

func GetFileModificationTime(path string) time.Time

GetFileModificationTime gets mtime of a file

func GetFileSize

func GetFileSize(path string) int64

GetFileSize gets the size of a file

func GetRelativePath

func GetRelativePath(dir, path string) string

GetRelativePath gets the relative path given path and directory

func GetTempFile

func GetTempFile(path string) string

GetTempFile gets a temp file name

func GetWorkDir

func GetWorkDir() string

GetWorkDir returns the directory where the executable file put

func IsPathDirectory

func IsPathDirectory(path string) bool

IsPathDirectory determines if a path is a directory

func IsPathExist

func IsPathExist(path string) bool

IsPathExist determines if a path exists

func IsPathFile

func IsPathFile(path string) bool

IsPathFile determines if a path is a file

func IsSubPath

func IsSubPath(subPath, path string) bool

IsSubPath checks if a path is under another one in directory manner case 1: gs://abc/def -> gs://abc/def : true case 2: gs://abc/def -> gs://abc/de : false case 3: gs://abc/def -> gs://abc/def/ : false case 4: gs://abc/def/-> gs://abc/def/ : true case 5: gs://abc/def/ghi -> gs://abc/def : true case 6: gs://abc/def/ghi -> gs://abc/de : false case 7: gs://abc/def/ghi -> gs://abc/def/ : true

func IsTempFile

func IsTempFile(path string) bool

IsTempFile checks if a file is temp file

func JoinPath

func JoinPath(dir string, parts ...string) string

JoinPath combines dir and parts into a new path

func ParseFile

func ParseFile(input string) (string, string)

ParseFile parses file into dir, name

func ParseObjectUrl added in v1.0.12

func ParseObjectUrl(url string) (scheme, bucket, prefix string, err error)

func ParseURL

func ParseURL(input string) (string, string, string)

ParseURL parses url into scheme, bucket, prefix

func Recovery

func Recovery()

Recovery recovers from exceptions

func SetFileModificationTime

func SetFileModificationTime(path string, mt time.Time)

SetFileModificationTime sets mtime to a file

func SetPrefixAsDirectory

func SetPrefixAsDirectory(prefix string) string

SetPrefixAsDirectory sets the prefix as directory

Types

type RetryConfig added in v1.0.28

type RetryConfig struct {
	MaxAttempts int           // Maximum number of attempts (including first attempt)
	Delay       time.Duration // Delay between retries
	Backoff     float64       // Multiplier for delay on each retry (1.0 = no backoff)
}

RetryConfig holds configuration for retry behavior

func DefaultRetryConfig added in v1.0.28

func DefaultRetryConfig() RetryConfig

DefaultRetryConfig returns a reasonable default retry configuration

Jump to

Keyboard shortcuts

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