GitHub - nikolaydubina/go-recipes: Handy commands to run in Go projects
source link: https://github.com/nikolaydubina/go-recipes
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
Go recipes
Handy commands to run in Go projects
Find Go versions of upstream modules
Use this when upgrading version of Go or finding old modules.
$ go list -deps -json ./... | jq -rc 'select(.Standard!=true and .Module.GoVersion!=null) | [.Module.GoVersion,.Module.Path] | join(" ")' | sort -V | uniq 1.14 github.com/grpc-ecosystem/go-grpc-middleware 1.14 github.com/grpc-ecosystem/grpc-gateway 1.14 go.uber.org/multierr 1.15 gopkg.in/yaml.v2 1.16 github.com/deliveryhero/pd-ersatz/sts 1.16 github.com/deliveryhero/pd-pablo-payment-gateway ...
Find upstream modules without Go version
Use this to find outdated modules or imports that you need to upgrade
$ go list -deps -json ./... | jq -rc 'select(.Standard!=true and .Module.GoVersion==null) | .Module.Path' | sort -u github.com/DataDog/datadog-go github.com/ajg/form github.com/davecgh/go-spew github.com/dgrijalva/jwt-go github.com/facebookgo/clock ...
Make histogram of Go files per package
Use this to see when package is too big or too small. Adjust histogram length to maximum value.
$ go list -json ./... | jq -rc '[.ImportPath, (.GoFiles | length | tostring)] | join(" ")' | perl -lane 'print (" " x (20 - $F[1]), "=" x $F[1], " ", $F[1], "\t", $F[0])' ================== 18 github.com/gin-gonic/gin ============= 13 github.com/gin-gonic/gin/binding = 1 github.com/gin-gonic/gin/ginS = 1 github.com/gin-gonic/gin/internal/bytesconv = 1 github.com/gin-gonic/gin/internal/json =========== 11 github.com/gin-gonic/gin/render
Find packages without tests
If code coverage does not report packages without tests. This should be fast and good for CI.
$ go list -json ./... | jq -rc 'select((.TestGoFiles | length)==0) | .ImportPath' github.com/gin-gonic/gin/ginS github.com/gin-gonic/gin/internal/json
Make graph of upstream packages
Use to find unexpected dependencies, visualize project. Works best for small number of packages, for large projects use
grep
to narrow down subgraph. Without-deps
only for current module.
$ go list -deps -json ./... | jq -c 'select(.Standard!=true) | {from: .ImportPath, to: .Imports[]}' | jsonl-graph | dot -Tsvg > package-graph.svg
Scrape details about upstream modules and make graph
Use to find low quality, unmaintained dependencies.
$ go mod graph | import-graph -i=gomod | jsonl-graph -color-scheme=file://$PWD/basic.json | dot -Tsvg > output.svg
Prerequisites
# get https://graphviz.org/download/ # get https://stedolan.github.io/jq/download/ $ go install github.com/nikolaydubina/jsonl-graph@latest $ go install github.com/nikolaydubina/import-graph@latest $ go mod download
Contributions
.. are welcomed!
Recommend
-
12
Run Custom Commands with PreprosSkip to content Learning is living ...
-
12
How To Run Commands In Stopped Docker Containers Executing a command in a running Docker container is a common task. But what about executing commands in a stopped container? Learn how to promote your stopped container as a...
-
8
-
3
How I set up my new Next.js projects with a handy bash script Jul 9 Originally published at
-
12
-
6
How can I use Java to run OS commands? advertisements I'm making a program and that must call Clafer with clafer...
-
5
Git Yourself Out of Trouble with These Handy Commands One of the most crucial skills to have when working on software projects is navigating Git, the seemi...
-
4
Small Fixed-Point Decimals (fp3.Decimal) When you have small and simple f...
-
5
mprocs mprocs runs multiple commands in parallel and shows output of each command separately. When you work on a project you very often need the same list of commands to be running. For example: webpack serve,...
-
4
10 Handy React.js Code Snippets for Your ProjectsBoost Your React.js Development with These Code SnippetsĀ Posted on October 3, 2023 Ā (Last modified on...
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK