Go / List Standard Packages
List Standard Packages
Lists all standard Go packages available for import.
go list std go list std #!/bin/bash
# List Standard Packages
go list std import subprocess
# List Standard Packages
# Make sure to replace <placeholders> with actual values
def run_command():
cmd = [
"go",
"list",
"std"
]
try:
print(f"Executing: {' '.join(cmd)}")
subprocess.run(cmd, check=True)
except subprocess.CalledProcessError as e:
print(f"Error: {e}")
except FileNotFoundError:
print("Error: go not found. Please install it first.")
if __name__ == "__main__":
run_command() When To Use
When assessing available libraries during code refactoring or architecting new features.
Pro Tip
Use the pattern `go list std/...` to list all packages hierarchically, optimizing large projects.
Anatomy of Output
Understanding the result
fmt /usr/local/go/src/fmt First Column - Package Name Name of the standard package.
/usr/local/go/src/fmt Second Column - Package Path Filesystem path to the package source.
Power User Variants
Optimized versions
go list std -json Provides detailed JSON output of all standard packages.
go list std --export Outputs exported symbols of each package.
Troubleshooting
Common pitfalls
go: cannot find package
Solution: Ensure your Go environment is properly set up and GOPATH is correct.
no Go files in directory
Solution: Navigate to a directory containing Go files or initialize a module.
go: no standard packages found
Solution: Check your Go installation for correctness.
Command Breakdown
What each part is doing
-
go - Base Command
- The executable that performs this operation. Here it runs Go before the shell applies any redirect operators.
Alternative Approaches
Comparable commands in other tools
Alternative programming tools for the same job.
adb -s <serial_number> install <path/to/file>.apk Adb / Grant App Permission adb shell pm grant <package> <android.permission.CAMERA|android.permission.ACCESS_FINE_LOCATION|android.permission.READ_CONTACTS|...> Adb / Clear Application Data Adb adb shell pm clear <package> Dotnet / Package Dotnet Application Single File dotnet publish -r <runtime_identifier> -p:PublishSingleFile=true <path/to/project_file> Adb / Revoke App Permission adb shell pm revoke <package> <android.permission.CAMERA|android.permission.ACCESS_FINE_LOCATION|android.permission.READ_CONTACTS|...>