liveBook · Manning

Dependency

As explained in Go in Practice, Second Edition

A dependency is a software package or module required by another package or module.

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

How Go in Practice, Second Edition covers it

How deep it goes
Defines dependencies, demonstrates runtime availability checks, and gives commands for version updates and transitive dependency inspection.
Examples
Demonstrates third-party packages, the fortune executable, go get, go mod tidy, and go mod graph.
What it assumes
Assumes basic Go application knowledge while introducing package management and dependency files through Go modules.
What you can do after
Diagnose missing executables and operate Go module versions with go get, go mod tidy, and go mod graph.
How it connects
Connects dependency management with Go modules, semantic versioning, transitive dependencies, PATH lookup, and runtime environment detection.

Also explained in

Compare how 27 books explain dependency →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Go in Practice, Second Edition. The section links point to the parts of the book it draws on.