Skip to content

Instantly share code, notes, and snippets.

@Rican7
Last active March 1, 2016 19:23
Show Gist options
  • Save Rican7/ab39b95d9d1c2640e125 to your computer and use it in GitHub Desktop.
Save Rican7/ab39b95d9d1c2640e125 to your computer and use it in GitHub Desktop.
List interface types for a Go project using Sift (https://sift-tool.org/)
#!/usr/bin/env sh
# NOTE! This requires the "Sift" tool, GNU "sed", and Go (Golang)
#
# https://sift-tool.org/
# https://github.com/svent/sift
# https://www.gnu.org/software/sed/
# https://golang.org/
# https://golang.org/cmd/go/#hdr-Show_documentation_for_package_or_symbol
# List all interfaces in a package (and subpackages)
sift --no-group --filename --no-line-number --ext='go' --exclude-files='*_test.go' 'type .* interface {'
# See documentation for each previously listed interface
sift --no-group --filename --no-line-number --ext='go' --exclude-files='*_test.go' 'type .* interface {' | sed 's/type \(.*\) interface {/\1/g' | sed 's/\(\(\w\+\/\)\?\(\w\+\)\/\)\?\w\+\.go:/\3./g' | sed 's/^\.//g' | xargs -L 1 go doc
# List all interfaces and methods in a package (and subpackages)
sift --no-group --filename --no-line-number --ext='go' --exclude-files='*_test.go' 'type .* interface {' | sed 's/type \(.*\) interface {/\1/g' | sed 's/\(\(\w\+\/\)\?\(\w\+\)\/\)\?\w\+\.go:/\3./g' | sed 's/^\.//g' | sort | xargs -L 1 go doc 2>/dev/null | sift --no-group --no-line-number '^(type|}|\t)'
# List all interfaces and methods in a package (and subpackages) with a package/import header (on Go 1.6+)
sift --no-group --filename --no-line-number --ext='go' --exclude-files='*_test.go' 'type .* interface {' | sed 's/type \(.*\) interface {/\1/g' | sed 's/\(\(\w\+\/\)\?\(\w\+\)\/\)\?\w\+\.go:/\3./g' | sed 's/^\.//g' | sort | xargs -L 1 go doc 2>/dev/null | sift --no-group --no-line-number '^(package|type|}|\t)'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment