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 ¶
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) } }
Output:
func (Go) TestSum ¶
🧪 Run gotestsum (Params: Path just like you pass to go test, ie ./..., pkg/, etc ). If gotestsum is not installed, it will install it.
- Test outputs junit, json, and coverfiles.
- Test shuffles and adds race flag.
- Test running manually like this from current repo: GOTEST_DISABLE_RACE=1 mage -d magefiles -w . -v go:testsum ./pkg/...
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("pkg")); 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) // } }
Output: