dslice computes a static program slice of Go source code. Given a set of root symbols (functions, types, methods, constants, or variables), it extracts the minimal syntactic subset of the program required to compile those roots.
Dependencies on internal packages are resolved recursively and inlined into the output.
dslice [flags] <symbol>
Flags:
-o string output file (default: stdout)
-name string output package name (default: inferred)
$ dslice fmt.Println
$ dslice golang.org/x/tools/go/packages.Package
$ dslice net/http.Client.Do
$ dslice -o slice.go encoding/json.Marshal
Static analysis only. No guarantees for reflection, interface dispatch, or plugins.
M. Weiser, "Program Slicing," Proceedings of the 5th International Conference on Software Engineering, pp. 439-449, IEEE Press, 1981. https://dl.acm.org/doi/10.5555/800078.802557