Documentation
¶
Index ¶
- Constants
- Variables
- func BuildVersion(Version, Commit, Date, BuiltBy string) string
- func ChmodFile(filePath string)
- func CreateLogger(verbose bool)
- func GetAlgorithmFromFilename(filename string) (string, bool)
- func GetHasher(algorithm string) (hash.Hash, error)
- func GetOSArch()
- func HashFile(assetPath, algorithm string) (string, error)
- func IsChecksumFile(filePath string) bool
- func ListSupportedAlgorithms() []string
- func MatchFile(file string) bool
- func ParseBinaryName(assetName string) (binaryName string)
- func ParseChecksumFile(checksumFilePath, targetFilename string) (string, error)
- func VerifyChecksum(assetPathOnDisk string, assetNameInChecksumFile string, ...) (bool, string, error)
- type ParsedArgs
Constants ¶
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 ¶
var ( // Global logger instance used across the package Logger *log.Logger )
Functions ¶
func BuildVersion ¶
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 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 ¶
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 ¶
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 ¶
HashFile calculates the specified checksum of a file. Returns the hex-encoded checksum string and an error if any occurs.
func IsChecksumFile ¶
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 ¶
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 ParseChecksumFile ¶
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