How To?

How to check if a program is installed or not?

import (
      "os/exec"
      "testing"
)

func isCommandAvailable(name string) bool {
      cmd := exec.Command("command", "-v", name)
      if err := cmd.Run(); err != nil {
              return false
      }
      return true
}
func TestIsCommandAvailable(t *testing.T) {
      if isCommandAvailable("ls") == false {
              t.Error("ls command does not exist!")
      }
      if isCommandAvailable("ls111") == true {
              t.Error("ls111 command should not exist!")
      }
}

How to know the path where a program is installed?

How to force go build to use vendor?

Use -mod vendor parameter while building.

Last updated

Was this helpful?