回答:
ソースディレクトリとコンパイル済みパッケージファイルを削除するだけで安全です。の下にあるソースディレクトリ$GOPATH/srcと、下にあるパッケージファイルを見つけます。$GOPATH/pkg/<architecture>例:$GOPATH/pkg/windows_amd64。
GOPATHです/usr/lib/go。
go
でパッケージ用に生成されたgo install(またはgo get)アーカイブファイルと実行可能バイナリを削除できますgo clean -i importpath...。これらは通常、それぞれ$GOPATH/pkgとの下にあり$GOPATH/binます。
以下の例のように、...パッケージに実行可能ファイルが含まれている場合、それはgo clean -i削除されるだけで、サブパッケージのアーカイブファイルは削除されないようgore/gocodeに見えるため、必ずimportpath に含めてください。
その後、ソースコードをから手動で削除する必要があります$GOPATH/src。
go cleanを-n実行せずに実行される内容を出力する予行演習のフラグがあるため、確実に確認できます(を参照go help clean)。また-r、依存関係を再帰的にクリーンアップする魅力的なフラグもあります。これは、多くの標準ライブラリアーカイブファイルを削除することが予行演習からわかるため、実際には使用したくないでしょう。
完全な例。必要に応じてスクリプトのベースにすることができます。
$ go get -u github.com/motemen/gore
$ which gore
/Users/ches/src/go/bin/gore
$ go clean -i -n github.com/motemen/gore...
cd /Users/ches/src/go/src/github.com/motemen/gore
rm -f gore gore.exe gore.test gore.test.exe commands commands.exe commands_test commands_test.exe complete complete.exe complete_test complete_test.exe debug debug.exe helpers_test helpers_test.exe liner liner.exe log log.exe main main.exe node node.exe node_test node_test.exe quickfix quickfix.exe session_test session_test.exe terminal_unix terminal_unix.exe terminal_windows terminal_windows.exe utils utils.exe
rm -f /Users/ches/src/go/bin/gore
cd /Users/ches/src/go/src/github.com/motemen/gore/gocode
rm -f gocode.test gocode.test.exe
rm -f /Users/ches/src/go/pkg/darwin_amd64/github.com/motemen/gore/gocode.a
$ go clean -i github.com/motemen/gore...
$ which gore
$ tree $GOPATH/pkg/darwin_amd64/github.com/motemen/gore
/Users/ches/src/go/pkg/darwin_amd64/github.com/motemen/gore
0 directories, 0 files
# If that empty directory really bugs you...
$ rmdir $GOPATH/pkg/darwin_amd64/github.com/motemen/gore
$ rm -rf $GOPATH/src/github.com/motemen/gore
この情報はgoGoバージョン1.5.1のツールに基づいていることに注意してください。
#!/bin/bash
goclean() {
local pkg=$1; shift || return 1
local ost
local cnt
local scr
# Clean removes object files from package source directories (ignore error)
go clean -i $pkg &>/dev/null
# Set local variables
[[ "$(uname -m)" == "x86_64" ]] \
&& ost="$(uname)";ost="${ost,,}_amd64" \
&& cnt="${pkg//[^\/]}"
# Delete the source directory and compiled package directory(ies)
if (("${#cnt}" == "2")); then
rm -rf "${GOPATH%%:*}/src/${pkg%/*}"
rm -rf "${GOPATH%%:*}/pkg/${ost}/${pkg%/*}"
elif (("${#cnt}" > "2")); then
rm -rf "${GOPATH%%:*}/src/${pkg%/*/*}"
rm -rf "${GOPATH%%:*}/pkg/${ost}/${pkg%/*/*}"
fi
# Reload the current shell
source ~/.bashrc
}
使用法:
# Either launch a new terminal and copy `goclean` into the current shell process,
# or create a shell script and add it to the PATH to enable command invocation with bash.
goclean github.com/your-username/your-repository