Go provides a way to determine why a package is used in your project or not. Note that it only checks for dependencies imported by your code.
If package is used, by your project files will show:
go mod why package1_name
# package1_name
yourmodule/dir1/dir2/main.go
yourmodule/dir1/dir2/main_test.go
Otherwise, it will say that the main modules doesn’t need it.
go mod why package2_name
# package2_name
(main module does not need package package2_name)