A dependency is a software package or module required by another package or module. Go’s dependency management incorporates third-party packages into applications, while runtime checks can reveal whether an external dependency is available on the host. section 1.1 section 12.4.1
Manage dependency versions and inspect the resulting graph with Go module commands:
- Select an exact semantic-version tag with go get package@version. section 6.1.3
- Update all dependencies with go get -u followed by go mod tidy. section 6.1.3
- Update one dependency with go get -u package; transitive dependencies may also change. section 6.1.3
- Inspect dependency versions and their own dependencies with go mod graph. section 6.1.3
Detecting a runtime dependency
func checkDep(name string) error { if _, err := exec.LookPath(name); err != nil { return fmt.Errorf("Could not find '%s' in PATH: %s", name, err) } return nil } err := checkDep("fortune") if err != nil { log.Fatalln(err) } fmt.Println("Time to get your fortune") This check reports a missing executable before the application tries to use it. section 12.4.1
Listing 12.11 Function to check whether the application is available
func checkDep(name string) error {
if _, err := exec.LookPath(name); err != nil { #1
es := "Could not find '%s' in PATH: %s" #2
return fmt.Errorf(es, name, err) #2
} #2
return nil #3
}
Inspect the complete Go function for checking whether an executable dependency is available through PATH. section 12.4.1


























