utils

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Sep 12, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CreateDirIfNotExists

func CreateDirIfNotExists(
	dirPath string,
) error

CreateDirIfNotExists checks if a directory path exists and creates all necessary parent directories if it does not.

Parameters:

  • dirPath: The path of the directory to be verified and created.

Returns:

  • error: An error if directory creation fails, or nil if successful/already existing.

func ExtractEmbedFS

func ExtractEmbedFS(
	embedFS embed.FS,
	targetDirPath string,
	replaceMode string,
	backup bool,
) error

ExtractEmbedFS extracts the directory structure and files from an embed.FS into a target directory.

Supported replaceMode strategies:

  • "none": If the local root target directory already exists, aborts extraction immediately without modifying files.
  • "all": Completely removes existing target directory contents and recreates all embedded files from scratch.
  • "miss": Only writes missing files and directories; keeps existing files intact without overwriting.
  • "changed": Compares SHA-256 hashes of local files against embedded ones and overwrites only modified files.

Parameters:

  • embedFS: The source embedded filesystem containing files to extract.
  • targetDirPath: Local destination directory where files will be written.
  • replaceMode: Strategy ("none", "all", "miss", "changed") determining overwrite behavior.
  • backup: When true, creates a timestamped backup copy of existing target directory before replacement.

Returns:

  • error: An error if directory scanning, backup creation, or file writing fails; nil on success.

func FindFilesInEmbedFS

func FindFilesInEmbedFS(
	embedFS embed.FS,
	pattern string,
) ([]string, error)

FindFilesInEmbedFS traverses an embedded filesystem and returns paths of files matching a glob or substring pattern.

Parameters:

  • embedFS: The embedded filesystem instance to search.
  • pattern: Glob pattern or case-insensitive substring to search for.

Returns:

  • matches: A slice of matching file paths relative to the embedded filesystem root.
  • err: An error if filesystem traversal encounters an issue.

func IsFileNewer

func IsFileNewer(
	pathFileA string,
	pathFileB string,
) (
	isANewer bool,
	newerPath string,
	olderPath string,
	err error,
)

IsFileNewer compares the modification timestamps of two local files.

Parameters:

  • pathFileA: Absolute or relative file path of the first file.
  • pathFileB: Absolute or relative file path of the second file.

Returns:

  • isANewer: True if pathFileA was modified more recently than pathFileB, false otherwise.
  • newerPath: The path of whichever file was modified more recently.
  • olderPath: The path of whichever file was modified earlier.
  • err: An error if os.Stat fails for either file.

Types

This section is empty.

Jump to

Keyboard shortcuts

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