Skip to content

Instantly share code, notes, and snippets.

@yfuruyama
Last active February 4, 2018 13:59
Show Gist options
  • Select an option

  • Save yfuruyama/6b057bba0639a1dcae08d08e8bf30084 to your computer and use it in GitHub Desktop.

Select an option

Save yfuruyama/6b057bba0639a1dcae08d08e8bf30084 to your computer and use it in GitHub Desktop.
List all installed go packages
#!/usr/bin/env perl
use strict;
use warnings;
use File::Find qw/find/;
sub _find_packages {
my $root = shift;
my $pkg_path = $root . '/pkg';
my @packages;
find(sub {
return unless $_ =~ m!\.a$!;
return if $File::Find::name =~ m!/internal/!;
my ($arch, $pkg) = $File::Find::name =~ m!${pkg_path}/([^/]+)/(.+)\.a$!;
push @packages, $pkg;
}, $pkg_path);
return @packages;
}
sub _uniq {
my %h = map { $_ => 1 } @_;
return keys(%h);
}
my @packages = ('builtin');
push(@packages, sort(_uniq(_find_packages($ENV{GOROOT}))));
push(@packages, sort(_uniq(_find_packages($ENV{GOPATH}))));
print($_ . "\n") for (@packages);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment