Documentation
¶
Overview ¶
Package beku provide library for managing Go packages in user's environment (GOPATH or vendor directory).
Index ¶
- Constants
- Variables
- func GetCompareURL(remoteURL, oldVer, newVer string) (url string)
- func IsDirEmpty(dir string) (ok bool)
- func IsFileExist(parent, relpath string) bool
- func IsIgnoredDir(name string) bool
- func IsTagVersion(version string) bool
- func RmdirEmptyAll(path string) error
- type Env
- func (env *Env) Exclude(importPaths []string)
- func (env *Env) Freeze() (err error)
- func (env *Env) GetPackage(importPath string) (pkg *Package, err error)
- func (env *Env) GetPackageFromDB(importPath, remoteURL string) (int, *Package)
- func (env *Env) GetUnused(srcPath string) (err error)
- func (env *Env) IsExcluded(importPath string) bool
- func (env *Env) Load(file string) (err error)
- func (env *Env) Query(pkgs []string)
- func (env *Env) Remove(rmPkg string, recursive bool) (err error)
- func (env *Env) Rescan(firstTime bool) (ok bool, err error)
- func (env *Env) Save(file string) (err error)
- func (env *Env) Scan() (err error)
- func (env *Env) String() string
- func (env *Env) Sync(pkgName, importPath string) (err error)
- func (env *Env) SyncAll() (err error)
- func (env *Env) SyncMany(pkgs []string) (err error)
- type Package
- func (pkg *Package) CheckoutVersion(newVersion string) (err error)
- func (pkg *Package) CompareVersion(newPkg *Package) (err error)
- func (pkg *Package) Fetch() (err error)
- func (pkg *Package) GetRecursiveImports(env *Env) (imports []string, err error)
- func (pkg *Package) GoClean() (err error)
- func (pkg *Package) GoInstall(env *Env) (err error)
- func (pkg *Package) Install() (err error)
- func (pkg *Package) IsEqual(other *Package) bool
- func (pkg *Package) Remove() (err error)
- func (pkg *Package) RemoveRequiredBy(importPath string) (ok bool)
- func (pkg *Package) Run(env *Env, cmds []string) (err error)
- func (pkg *Package) Scan() (err error)
- func (pkg *Package) ScanBuild() (cmd vendorMode)
- func (pkg *Package) ScanDeps(env *Env) (err error)
- func (pkg *Package) String() string
- func (pkg *Package) Update(newPkg *Package) (err error)
- func (pkg *Package) UpdateMissingDep(newPkg *Package, addAsDep bool) (found bool)
Constants ¶
const ( DebugL1 debugMode = 1 << iota DebugL2 )
List of debug levels.
const ( // DefDBName define default database name, where the dependencies will // be saved and loaded. DefDBName = "beku.db" )
const (
VCSModeGit = "git"
)
Variables ¶
var ( ErrGOROOT = errors.New("GOROOT is not defined") // ErrVersion define an error when directory have VCS metadata (e.g. // `.git` directory) but did not have any tag or commit. ErrVersion = errors.New("No tag or commit found") // ErrRemote define an error when package remote URL is empty or // invalid. ErrRemote = errors.New("Empty or invalid remote URL found") // ErrPackageName define an error if package name is empty or invalid. ErrPackageName = errors.New("Empty or invalid package name") )
List of error messages.
var ( // Debug level for this package. Set from environment variable // BEKU_DEBUG. Debug debugMode )
Functions ¶
func GetCompareURL ¶
GetCompareURL return the URL that compare two versions of package from given remote URL. Remote URL can be in git format ("git@github.com:<username>/<reponame>") or in HTTP format.
On package that hosted on Github, the compare URL format is,
https://github.com/<username>/<reponame>/compare/<old-version>...<new-version>
func IsDirEmpty ¶
IsDirEmpty will return true if directory is not exist or empty; otherwise it will return false.
func IsFileExist ¶ added in v0.3.0
IsFileExist will return true if relative path is exist on parent directory; otherwise it will return false.
func IsIgnoredDir ¶
IsIgnoredDir will return true if directory start with "_" or ".", or equal with "vendor" or "testdata"; otherwise it will return false.
func IsTagVersion ¶
IsTagVersion return true if "version" prefixed with "v" or contains at least one dot "." character.
func RmdirEmptyAll ¶
RmdirEmptyAll remove directory in path if it's empty until one of the parent is not empty.
Types ¶
type Env ¶
type Env struct { NoConfirm bool // contains filtered or unexported fields }
Env contains the environment of Go including GOROOT source directory, package root directory (prefix), list of packages, list of standard packages, and list of missing packages.
func NewEnvironment ¶
NewEnvironment will gather all information in user system.
func (*Env) Exclude ¶ added in v0.2.0
Exclude mark list of packages to be excluded from future operations.
func (*Env) Freeze ¶
Freeze all packages in database. Install all registered packages in database and remove non-registered from "src" and "pkg" directories.
func (*Env) GetPackage ¶
GetPackage will return installed package from system.
func (*Env) GetPackageFromDB ¶
GetPackageFromDB will return index and pointer to package in database. If no package found, it will return -1 and nil.
func (*Env) GetUnused ¶
GetUnused will get all non-registered packages from "src" directory, without including all excluded packages.
func (*Env) IsExcluded ¶ added in v0.2.0
IsExcluded will return true if import path is registered as one of excluded package; otherwise it will return false.
func (*Env) Query ¶
Query the package database. If package is not empty, it will only show the information about that package.
func (*Env) Remove ¶
Remove package from environment. If recursive is true, it will also remove their dependencies, as long as they are not required by other package.
func (*Env) Sync ¶
Sync will download and install a package including their dependencies. If the importPath is defined, it will be downloaded into that directory.
(1) First, we check if pkgName contains version. (2) And then we check if package already installed, by comparing with database. (2.1) If package already installed, do an update. (2.2) If package is not installed, clone the repository into `importPath`, and checkout the latest tag or the latest commit.
type Package ¶
type Package struct { ImportPath string FullPath string ScanPath string RemoteName string RemoteURL string Version string VersionNext string DepsMissing []string Deps []string RequiredBy []string // contains filtered or unexported fields }
Package define Go package information: path to package, version, whether is tag or not, and VCS mode.
func NewPackage ¶
NewPackage create a package set the package version, tag status, and dependencies.
func (*Package) CheckoutVersion ¶
CheckoutVersion will set the package version to new version.
func (*Package) CompareVersion ¶
CompareVersion will compare package version using current package as base.
func (*Package) Fetch ¶
Fetch will try to update the package and get the latest version (tag or commit).
func (*Package) GetRecursiveImports ¶
GetRecursiveImports will get all import path recursively using `go list` and return it as slice of string without any duplication.
func (*Package) GoInstall ¶
GoInstall a package recursively ("./...").
(1) Set PATH to let go install that require gcc work when invoked from non-interactive shell (e.g. buildbot).
func (*Package) Install ¶
Install a package. Clone package "src" directory, set to the latest tag if exist or to the latest commit, and scan dependencies.
func (*Package) IsEqual ¶
IsEqual will return true if current package have the same import path, remote name, remote URL, and version with other package; otherwise it will return false.
func (*Package) RemoveRequiredBy ¶
RemoveRequiredBy will remove package importPath from list of required-by. It will return true if importPath is removed from list, otherwise it will return false.
func (*Package) Scan ¶
Scan will set the package version, `isTag` status, and remote URL using metadata in package repository.
func (*Package) ScanBuild ¶ added in v0.3.0
func (pkg *Package) ScanBuild() (cmd vendorMode)
ScanBuild files on package root directory. The following build files is known by beku,
* Godeps: gdm * Gopkg.toml: dep
func (*Package) ScanDeps ¶
ScanDeps will scan package dependencies, removing standard packages, keep only external dependencies.
func (*Package) Update ¶
Update the current package to the new package. The new package may contain new remote or new version.
func (*Package) UpdateMissingDep ¶
UpdateMissingDep will remove missing package if it's already provided by new package import-path.
If "addAsDep" is true, it will also, (1) add new package as one of package dependencies of current package, and (2) add current package as required by new package.
It will return true if new package solve the missing deps on current package, otherwise it will return false.