Documentation
¶
Overview ¶
Provide Go linting, formatting and other basic tooling.
Some additional benefits to using this over calling natively are:
- Uses improved gofumpt over gofmt.
- Uses golines with `mage go:wrap` to automatically wrap long expressions.
- If the non-standard tooling isn't installed, it will automatically go install the required tool on calling, reducing the need to run setup processes.
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AddGoPkgBinToPath ¶
func AddGoPkgBinToPath() error
AddGoPkgBinToPath ensures the go/bin directory is available in path for cli tooling.
func QualifyGoBinary ¶
QualifyGoBinary provides a fully qualified path for an installed Go binary to avoid path issues.
Types ¶
type Go ¶
func (Go) Fmt ¶
✨ Fmt runs gofumpt. Export SKIP_GOLINES=1 to skip golines. Important. Make sure golangci-lint config disables gci, goimports, and gofmt. This will perform all the sorting and other linters can cause conflicts in import ordering.
func (Go) GetModuleName ¶
getModuleName returns the name from the module file. Original help on this was: https://stackoverflow.com/a/63393712/68698
func (Go) LintConfig ¶
🏥 LintConfig will return output of golangci-lint config.
func (Go) Test ¶
🧪 Run go test. Optional: GOTEST_FLAGS '-tags integration', Or write your own GOTEST env logic. Example of checking based on GOTEST style environment variable:
if !strings.Contains(strings.ToLower(os.Getenv("GOTESTS")), "slow") {
t.Skip("GOTESTS should include 'slow' to run this test")
}.
Example ¶
package main
import (
"os"
"strings"
"github.com/pterm/pterm"
"github.com/sheldonhull/magetools/gotools"
)
func main() {
pterm.DisableOutput()
if !strings.Contains(strings.ToLower(os.Getenv("GOTESTS")), "superslow") {
return
// t.Skip("GOTESTS should include 'slow' to run this test")
}
// Running as mage task
if err := (gotools.Go{}.Test()); err != nil {
pterm.Error.Printf("ExampleGo_Test: %v\n", err)
}
// Running with GOTEST_FLAGS detection
os.Setenv("GOTEST_FLAGS", "-tags=integration")
if err := (gotools.Go{}.Test()); err != nil {
pterm.Error.Printf("ExampleGo_Test: %v\n", err)
}
}
func (Go) TestSum ¶
🧪 Run gotestsum.
Example ¶
package main
import (
"os"
"strings"
"github.com/pterm/pterm"
"github.com/sheldonhull/magetools/gotools"
)
func main() {
pterm.DisableOutput()
if !strings.Contains(strings.ToLower(os.Getenv("GOTESTS")), "superslow") {
return
// t.Skip("GOTESTS should include 'slow' to run this test")
}
// Running as mage task
if err := (gotools.Go{}.TestSum()); err != nil {
pterm.Error.Printf("ExampleGo_TestSum: %v\n", err)
}
// Running with GOTEST_FLAGS detection
// os.Setenv("GOTEST_FLAGS", "-tags=integration")
// if err := (gotools.Go{}.TestSum()); err != nil {
// pterm.Error.Printf("ExampleGo_TestSum: %v", err)
// }
}