Skip to content

Instantly share code, notes, and snippets.

@maxsei
Created October 25, 2022 19:28
Show Gist options
  • Select an option

  • Save maxsei/6214f0a3d1416a65ec12279dcf93f1ad to your computer and use it in GitHub Desktop.

Select an option

Save maxsei/6214f0a3d1416a65ec12279dcf93f1ad to your computer and use it in GitHub Desktop.
list out all the local golang files that depend on a package
PKG_PATH="./path/relative/to/your/go/pkg"
go list -f '{{ with $modstr := (printf "%v" $.Module) -}}
{{ range $_, $dep := $.Deps -}}
{{ if ne (slice (printf "%v%v" (module $dep) $modstr) 0 (len $modstr)) $modstr -}}
{{ continue -}}
{{ end -}}
{{ println $dep -}}
{{ end -}}
{{ end -}}
{{ .Dir -}}' $PKG_PATH | xargs -L 1 go list -f '{{ range .GoFiles -}}
{{ printf "%s/%s\n" $.Dir . -}}
{{ end -}}' | xargs -L 1 realpath
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment