utils

package
v0.0.0-...-66962f2 Latest Latest
Warning

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

Go to latest
Published: Aug 30, 2026 License: MIT Imports: 21 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// DefaultAlgorithmForGenericChecksums is the algorithm assumed for generic checksum files
	// like "checksums.txt" when the algorithm cannot be derived from the filename.
	// GoReleaser uses SHA256 for its generic `_checksums.txt` file.
	DefaultAlgorithmForGenericChecksums             = "sha256"
	S_IXUSR                             os.FileMode = 0o100 // Execute by owner
	S_IXGRP                             os.FileMode = 0o010 // Execute by group
	S_IXOTH                             os.FileMode = 0o001 // Execute by others
)

Variables

View Source
var (
	// Global logger instance used across the package
	Logger *log.Logger
)

Functions

func BuildVersion

func BuildVersion(Version, Commit, Date, BuiltBy string) string

BuildVersion constructs a formatted version string using build information. It combines the application version with details about the build environment and compilation settings for diagnostic and informational purposes.

-Version: The semantic version of the application (e.g., "v1.0.0"). -Commit: The Git commit hash of the source code used for the build. -Date: The timestamp when the build was created. -BuiltBy: The entity (person, CI system) that created the build. Returns: A multi-line string containing formatted version and build information.

func ChmodFile

func ChmodFile(filePath string)

func CreateLogger

func CreateLogger(verbose bool)

CreateLogger creates and configures the package-level Logger instance based on the desired verbosity. This function can create a new logger or reconfigure an existing one.

-verbose: Boolean indicating if debug-level logging should be enabled.

func GetAlgorithmFromFilename

func GetAlgorithmFromFilename(filename string) (string, bool)

GetAlgorithmFromFilename attempts to derive the hash algorithm name (e.g., "sha256") from a filename, typically by looking at its extension (e.g., ".sha256"). It returns the algorithm name and true if a recognized algorithm extension is found.

func GetHasher

func GetHasher(algorithm string) (hash.Hash, error)

GetHasher returns a new hash.Hash instance for the given algorithm, mirroring GoReleaser's supported algorithms and their specific instantiations.

func GetOSArch

func GetOSArch()

GetOSArch identifies the current operating system and architecture, and creates a set of regular expressions to match appropriate release assets. This prepares the system to identify assets that are compatible with the current machine.

func HashFile

func HashFile(assetPath, algorithm string) (string, error)

HashFile calculates the specified checksum of a file. Returns the hex-encoded checksum string and an error if any occurs.

func IsChecksumFile

func IsChecksumFile(filePath string) bool

IsChecksumFile checks if the given filename indicates a checksum file based on common checksum manifest filenames or recognized algorithm extensions.

func ListSupportedAlgorithms

func ListSupportedAlgorithms() []string

ListSupportedAlgorithms returns a slice of algorithm name strings that GetHasher supports.

func MatchFile

func MatchFile(file string) bool

MatchFile checks if a filename matches the current OS and architecture patterns. This determines if the given file is likely compatible with the current system.

-file: The filename to check against OS/architecture patterns. Returns: true if the file matches any of the OS/architecture patterns, false otherwise.

func ParseBinaryName

func ParseBinaryName(assetName string) (binaryName string)

func ParseChecksumFile

func ParseChecksumFile(checksumFilePath, targetFilename string) (string, error)

ParseChecksumFile (your existing function) Note: For matching, `targetFilename` should ideally be the base name of the file, as checksum files usually list base names.

func VerifyChecksum

func VerifyChecksum(
	assetPathOnDisk string,
	assetNameInChecksumFile string,
	checksumFilePath string,
	defaultAlgoForGeneric string,
) (bool, string, error)

VerifyChecksum verifies a local asset against a checksum file. It attempts to determine the algorithm from the checksum file's name. If the checksum file has a generic name (e.g., "project_version_checksums.txt"), it uses `defaultAlgoForGeneric` (which should typically be "sha256" for GoReleaser). In utils/checksum.go or utils/hash.go func VerifyChecksum(assetPathOnDisk string, assetNameInChecksumFile string, checksumFilePath string, defaultAlgoForGeneric string) (bool, string, error) assetPathOnDisk: The full path to the file on the local disk whose checksum needs to be calculated. assetNameInChecksumFile: The name of the asset as it appears in the checksum file.

Types

type ParsedArgs

type ParsedArgs struct {
	Owner   string // Repository owner (user or organization)
	Repo    string // Repository name
	Version string // Will be "latest" or a specific tag
}

ParsedArgs holds the parsed components of the argument string. This represents the GitHub repository and version information.

func ParseArgs

func ParseArgs(argString string) (ParsedArgs, error)

ParseArgs parses an argument string in the format owner/repo[@version]. Supported formats: - owner/repo (version defaults to "latest") - owner/repo@latest - owner/repo@vX.Y.Z (or any other tag)

-argString: The input string to parse. Returns:

  • ParsedArgs: A struct containing the parsed components
  • error: An error if the format is invalid

Jump to

Keyboard shortcuts

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