manager

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Aug 24, 2025 License: Apache-2.0, MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// GOARCHEnvVar is the environment variable for the Go runtime architecture.
	GOARCHEnvVar = "GOARCH"
	// GOOSEnvVar is the environment variable for the Go runtime operating
	// system.
	GOOSEnvVar = "GOOS"
)

Variables

View Source
var (
	// ErrBinaryAlreadyManaged is returned when a binary is already managed.
	ErrBinaryAlreadyManaged = errors.New("binary already managed")
)

Functions

This section is empty.

Types

type BinaryManager

type BinaryManager interface {
	// DiagnoseBinary diagnoses issues in a binary.
	DiagnoseBinary(
		ctx context.Context,
		path string,
	) (model.BinaryDiagnostic, error)
	// GetAllBinaryInfos gets all binary infos.
	GetAllBinaryInfos(
		managed bool,
	) ([]model.BinaryInfo, error)
	// GetBinaryInfo gets the binary info for a given path.
	GetBinaryInfo(
		path string,
	) (model.BinaryInfo, error)
	// GetBinaryRepository gets the repository URL for a given binary.
	GetBinaryRepository(
		ctx context.Context,
		bin model.Binary,
	) (string, error)
	// GetBinaryUpgradeInfo gets the upgrade information for a given binary.
	GetBinaryUpgradeInfo(
		ctx context.Context,
		info model.BinaryInfo,
		checkMajor bool,
	) (model.BinaryUpgradeInfo, error)
	// InstallPackage installs a package.
	InstallPackage(
		ctx context.Context,
		pkg model.Package,
		kind model.Kind,
		rebuild bool,
	) error
	// MigrateBinary migrates a binary to be managed internally.
	MigrateBinary(
		path string,
	) error
	// PinBinary pins a binary to the Go binary directory with the given kind.
	PinBinary(
		bin model.Binary,
		kind model.Kind,
	) error
	// PruneBinary prunes binaries from the internal binary directory.
	PruneBinary(
		bin model.Binary,
	) error
	// UninstallBinary uninstalls a binary.
	UninstallBinary(
		bin model.Binary,
	) error
	// UpgradeBinary upgrades a binary.
	UpgradeBinary(
		ctx context.Context,
		binFullPath string,
		majorUpgrade bool,
		rebuild bool,
	) error
}

BinaryManager is an interface for a binary manager.

type GoBinaryManager

type GoBinaryManager struct {
	// contains filtered or unexported fields
}

GoBinaryManager is a manager for Go binaries.

func NewGoBinaryManager

func NewGoBinaryManager(
	fs system.FileSystem,
	runtime system.Runtime,
	toolchain toolchain.Toolchain,
	workspace system.Workspace,
) *GoBinaryManager

NewGoBinaryManager creates a new GoBinaryManager.

func (*GoBinaryManager) DiagnoseBinary

func (m *GoBinaryManager) DiagnoseBinary(
	ctx context.Context,
	path string,
) (model.BinaryDiagnostic, error)

DiagnoseBinary diagnoses a binary leveraging the toolchain. It returns the diagnostic results, or an error if the binary cannot be diagnosed (e.g. the binary is not a Go binary, the build info cannot be read, or the binary was built without Go modules). It also checks for vulnerabilities in the binary.

func (*GoBinaryManager) GetAllBinaryInfos

func (m *GoBinaryManager) GetAllBinaryInfos(managed bool) ([]model.BinaryInfo, error)

GetAllBinaryInfos gets all binary infos in the Go binary directory or managed binaries only if managed is true. It returns a list of binary infos, or an error if the binary directory cannot be determined or listed. It skips silently failures to get the binary info.

func (*GoBinaryManager) GetBinaryInfo

func (m *GoBinaryManager) GetBinaryInfo(path string) (model.BinaryInfo, error)

GetBinaryInfo gets the binary info for a given path leveraging the toolchain. It constructs the binary info from the binary's build info. It fails if the binary does not exist, is not a Go binary, or the binary was built without Go modules.

func (*GoBinaryManager) GetBinaryRepository

func (m *GoBinaryManager) GetBinaryRepository(
	ctx context.Context,
	bin model.Binary,
) (string, error)

GetBinaryRepository gets the repository URL for a binary leveraging the toolchain. It returns the repository URL from the module origin, falling back to the default repository URL if the module origin is not available.

func (*GoBinaryManager) GetBinaryUpgradeInfo

func (m *GoBinaryManager) GetBinaryUpgradeInfo(
	ctx context.Context,
	info model.BinaryInfo,
	checkMajor bool,
) (model.BinaryUpgradeInfo, error)

GetBinaryUpgradeInfo gets the upgrade information for a binary leveraging the toolchain. It first checks if the binary has a minor version upgrade available. Then, if the checkMajor flag is set, it checks if the binary has a major version upgrade available. It returns the upgrade information, or an error if the upgrade information cannot be determined (e.g. the module is not found).

func (*GoBinaryManager) InstallPackage

func (m *GoBinaryManager) InstallPackage(
	ctx context.Context,
	pkg model.Package,
	kind model.Kind,
	rebuild bool,
) error

InstallPackage installs a package leveraging the toolchain. If kind is major or minor, it pins the binary to the Go binary directory with the given kind. If rebuild is true, it rebuilds the binary.

func (*GoBinaryManager) MigrateBinary

func (m *GoBinaryManager) MigrateBinary(path string) error

MigrateBinary migrates a binary to be managed internally. It gets the binary info, moves the binary from the go bin path to the internal bin path, and creates a symlink to the go bin path.

func (*GoBinaryManager) PinBinary

func (m *GoBinaryManager) PinBinary(bin model.Binary, kind model.Kind) error

PinBinary pins a binary to the Go binary directory with the given kind. It creates a symlink to the binary in the Go binary directory with names binary, binary-major, or binary-major.minor if kind is latest, major, or minor respectively.

func (*GoBinaryManager) PruneBinary

func (m *GoBinaryManager) PruneBinary(bin model.Binary) error

PruneBinary prunes binaries from the internal binary directory identified by the given binary when not pinned. It returns an error if binaries cannot be listed, retrieved, or removed.

func (*GoBinaryManager) UninstallBinary

func (m *GoBinaryManager) UninstallBinary(bin model.Binary) error

UninstallBinary uninstalls a binary by removing the binary file. It removes the binary from the go bin path for unmanaged binaries, or removes the symlink for managed binaries. It returns an error if the binary cannot be found or removed.

func (*GoBinaryManager) UpgradeBinary

func (m *GoBinaryManager) UpgradeBinary(
	ctx context.Context,
	binFullPath string,
	majorUpgrade bool,
	rebuild bool,
) error

UpgradeBinary upgrades a binary leveraging the toolchain. It gets the binary info and upgrade info, and installs the binary if an upgrade is available or if the rebuild flag is set.

Directories

Path Synopsis