This Go package provides a simple utility to count the total number of lines and functions in .go files within a specified directory. It's useful for getting a quick overview of the size and complexity of a Go project.
- Counts the total number of lines in
.gofiles. - Counts the total number of functions in
.gofiles. - Supports counting metrics for all
.gofiles in a specified directory and its subdirectories.
To use this package, run the main.go file with the path to the directory you want to analyze as an argument. If you want to analyze the current directory, use ..
go run main.go <path>or
go run main.go .You can install GoMetrics by running the following command:
go install github.com/lacolle87/gometrics@v0.5.0This will install the package and make the gometrics executable available in your $GOPATH/bin directory.
After installation, you can run the gometrics executable with the desired path:
gometrics <path>Replace <path> with the path to the directory you want to analyze. If you want to analyze the current directory, use ..
The output will look something like this:
Project Name: myproject
-------------
Lines in main.go: 100; Functions: 20
Lines in utils.go: 50; Functions: 10
-------------
Total lines: 150; Total functions: 30
- Go 1.23 or later