Documentation ¶
Index ¶
- func Compile(buildPath string, goOS string, goArch string) error
- func FindExportedFuncsWithoutTests(pkgPath string) ([]string, error)
- func GHRelease(newVer string) error
- func GoReleaser() error
- func InstallGoDeps(deps []string) error
- func InstallVSCodeModules() error
- func ModUpdate(recursive bool, v bool) error
- func Tidy() error
- func UpdateMageDeps(magedir string) error
- type FuncInfo
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Compile ¶ added in v2.0.2
Compile builds a Go application for a specified operating system and architecture. It sets the appropriate environment variables and runs `go build`. The compiled application is placed in the specified build path.
**Parameters:**
buildPath: The output directory for the compiled application. goOS: The target operating system (e.g., "linux", "darwin", "windows"). goArch: The target architecture (e.g., "amd64", "arm64").
**Returns:**
error: An error if the compilation process encounters one.
Example ¶
package main import ( "fmt" "log" mageutils "github.com/l50/goutils/v2/dev/mage" ) func main() { buildPath := "/path/to/output/directory" goOS := "linux" goArch := "amd64" if err := mageutils.Compile(buildPath, goOS, goArch); err != nil { log.Fatalf("failed to compile: %v", err) } fmt.Printf("application compiled successfully at: %s\n", buildPath) }
Output:
func FindExportedFuncsWithoutTests ¶
FindExportedFuncsWithoutTests discovers all exported functions in a given package path that lack corresponding tests.
**Parameters:**
pkgPath: A string defining the package path to search.
**Returns:**
[]string: A slice of strings containing the names of exported functions that lack corresponding tests.
error: An error if there was a problem parsing the package or finding the tests.
Example ¶
package main import ( "fmt" "log" mageutils "github.com/l50/goutils/v2/dev/mage" ) func main() { funcs, err := mageutils.FindExportedFuncsWithoutTests("github.com/myorg/mypackage") if err != nil { log.Fatalf("failed to find exported functions without tests: %v", err) } for _, funcName := range funcs { fmt.Println(funcName) } }
Output:
func GHRelease ¶
GHRelease creates a new release on GitHub using the given new version. It requires the gh CLI tool to be available on the PATH.
**Parameters:**
newVer: A string specifying the new version, e.g., "v1.0.1"
**Returns:**
error: An error if the GHRelease function is not successful.
Example ¶
package main import ( "log" mageutils "github.com/l50/goutils/v2/dev/mage" ) func main() { newVer := "v1.0.1" if err := mageutils.GHRelease(newVer); err != nil { log.Fatalf("failed to create new GH release: %v", err) } }
Output:
func GoReleaser ¶
func GoReleaser() error
GoReleaser runs the Goreleaser tool to generate all the supported binaries specified in a .goreleaser configuration file.
**Returns:**
error: An error if the Goreleaser function is not successful.
Example ¶
Example GoReleaser
package main import ( "log" mageutils "github.com/l50/goutils/v2/dev/mage" ) func main() { if err := mageutils.GoReleaser(); err != nil { log.Fatalf("failed to run GoReleaser: %v", err) } }
Output:
func InstallGoDeps ¶
InstallGoDeps installs the specified Go dependencies by executing 'go install' for each dependency.
**Parameters:**
deps: A slice of strings defining the dependencies to install.
**Returns:**
error: An error if the InstallGoDeps function didn't run successfully.
Example ¶
package main import ( "log" mageutils "github.com/l50/goutils/v2/dev/mage" ) func main() { deps := []string{"github.com/stretchr/testify", "github.com/go-chi/chi"} if err := mageutils.InstallGoDeps(deps); err != nil { log.Fatalf("failed to install Go dependencies: %v", err) } }
Output:
func InstallVSCodeModules ¶
func InstallVSCodeModules() error
InstallVSCodeModules installs the modules used by the vscode-go extension in Visual Studio Code.
**Returns:**
error: An error if the InstallVSCodeModules function is not successful.
Example ¶
package main import ( "log" mageutils "github.com/l50/goutils/v2/dev/mage" ) func main() { if err := mageutils.InstallVSCodeModules(); err != nil { log.Fatalf("failed to install VS Code modules: %v", err) } }
Output:
func ModUpdate ¶
ModUpdate updates go modules by running 'go get -u' or 'go get -u ./...' if recursive is set to true. The function will run in verbose mode if 'v' is set to true.
**Parameters:**
recursive: A boolean specifying whether to run the update recursively. v: A boolean specifying whether to run the update in verbose mode.
**Returns:**
error: An error if the ModUpdate function is not successful.
Example ¶
package main import ( "log" mageutils "github.com/l50/goutils/v2/dev/mage" ) func main() { recursive := true verbose := true if err := mageutils.ModUpdate(recursive, verbose); err != nil { log.Fatalf("failed to update modules: %v", err) } }
Output:
func Tidy ¶
func Tidy() error
Tidy executes 'go mod tidy' to clear the module dependencies.
**Returns:**
error: An error if the Tidy function didn't run successfully.
Example ¶
package main import ( "log" mageutils "github.com/l50/goutils/v2/dev/mage" ) func main() { if err := mageutils.Tidy(); err != nil { log.Fatalf("failed to tidy modules: %v", err) } }
Output:
func UpdateMageDeps ¶
UpdateMageDeps modifies the dependencies in a given Magefile directory. If no directory is provided, it falls back to the 'magefiles' directory.
**Parameters:**
magedir: A string defining the path to the magefiles directory.
**Returns:**
error: An error if the UpdateMageDeps function didn't run successfully.
Example ¶
package main import ( "log" mageutils "github.com/l50/goutils/v2/dev/mage" ) func main() { magedir := "custom/mage/dir" if err := mageutils.UpdateMageDeps(magedir); err != nil { log.Fatalf("failed to update Mage dependencies: %v", err) } }
Output:
Types ¶
type FuncInfo ¶
type FuncInfo struct { FilePath string // FilePath is the file path of the source file containing the function declaration. FuncName string // FuncName is the name of the exported function. }
FuncInfo represents information about an exported function within a Go package.
**Attributes:**
FilePath: A string representing the path to the source file containing the function declaration. FuncName: A string representing the name of the exported function.
func FindExportedFunctionsInPackage ¶
FindExportedFunctionsInPackage finds all exported functions in a given Go package by parsing all non-test Go files in the package directory. It returns a slice of FuncInfo structs. Each contains the file path and the name of an exported function. If no exported functions are found in the package, an error is returned.
**Parameters:**
pkgPath: A string representing the path to the directory containing the package to search for exported functions.
**Returns:**
[]FuncInfo: A slice of FuncInfo structs, each containing the file path and the name of an exported function found in the package. error: An error if no exported functions are found.
Example ¶
package main import ( "log" mageutils "github.com/l50/goutils/v2/dev/mage" ) func main() { packagePath := "/path/to/your/go/package" funcs, err := mageutils.FindExportedFunctionsInPackage(packagePath) if err != nil { log.Fatalf("failed to find exported functions: %v", err) } for _, f := range funcs { log.Printf("Exported function %s found in file %s\n", f.FuncName, f.FilePath) } }
Output: