mageutils

package
v2.0.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 11, 2023 License: MIT Imports: 12 Imported by: 0

README

goutils/v2/dev

The dev package is a part of goutils library. It provides utility functions for development-oriented operations in Go.


Functions

GHRelease
func GHRelease(newVer string) error

Create a new release on GitHub with the given new version.

GoReleaser
func GoReleaser() error

Run the Goreleaser tool to generate all the supported binaries specified in a .goreleaser configuration file.

InstallVSCodeModules
func InstallVSCodeModules() error

Installs the modules used by the vscode-go extension in Visual Studio Code.

ModUpdate
func ModUpdate(recursive bool, v bool) error

Updates go modules by running go get -u or go get -u ./... if recursive is set to true.

Tidy
func Tidy() error

Run go mod tidy to clean up the module dependencies.

UpdateMageDeps
func UpdateMageDeps(magedir string) error

Update the dependencies in a specified Magefile directory.

InstallGoDeps
func InstallGoDeps(deps []string) error

Install the specified Go dependencies by running go install for each dependency.

FindExportedFunctionsInPackage
func FindExportedFunctionsInPackage(pkgPath string) ([]FuncInfo, error)

Find all exported functions in a given Go package by recursively parsing all non-test Go files in the package directory.

FindExportedFuncsWithoutTests
func FindExportedFuncsWithoutTests(pkgPath string) ([]string, error)

Finds all exported functions in a given package path that do not have corresponding tests.


Installation

To use the goutils/v2/dev package, you need to install it via go get:

go get github.com/l50/goutils/v2/dev

Usage

After installation, you can import it in your project:

import "github.com/l50/goutils/v2/dev"

Tests

To run the tests for the goutils/v2/dev package, navigate to your $GOPATH/src/github.com/l50/goutils/v2/dev directory and run go test:

go test -v

Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.


License

This project is licensed under the MIT License - see the LICENSE file for details.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Compile added in v2.0.2

func Compile(buildPath string, goOS string, goArch string) error

Compile builds a Go application for a specified operating system and architecture by setting the appropriate environment variables and running `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:

buildPath := "/path/to/output/directory" goOS := "linux" goArch := "amd64" err := Compile(buildPath, goOS, goArch)

if err != nil {
  log.Fatalf("failed to compile: %v", err)
}

fmt.Printf("Application compiled successfully at: %s\n", buildPath)

func FindExportedFuncsWithoutTests

func FindExportedFuncsWithoutTests(pkgPath string) ([]string, error)

FindExportedFuncsWithoutTests finds all exported functions in a given package path that do not have corresponding tests.

Parameters:

pkgPath: A string specifying the package path to search.

Returns:

[]string: A slice of strings containing the names of exported functions that do not have corresponding tests.

error: An error if there was a problem parsing the package or finding the tests.

Example:

funcs, err := 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)
}

func GHRelease

func GHRelease(newVer string) error

GHRelease creates a new release on GitHub with the given new version. It requires that the gh CLI tool is 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 was not successful.

Example:

newVer := "v1.0.1" err := GHRelease(newVer)

if err != nil {
  log.Fatalf("failed to create new GH release: %v", err)
}

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 was not successful.

Example:

err := GoReleaser()

if err != nil {
  log.Fatalf("failed to run GoReleaser: %v", err)
}

func InstallGoDeps

func InstallGoDeps(deps []string) error

InstallGoDeps installs the specified Go dependencies by running 'go install' for each dependency.

Parameters:

deps: A slice of strings specifying the dependencies to install.

Returns:

error: An error if the InstallGoDeps function was not successful.

Example:

deps := []string{"github.com/stretchr/testify", "github.com/go-chi/chi"} err := InstallGoDeps(deps)

if err != nil {
  log.Fatalf("failed to install Go dependencies: %v", err)
}

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 was not successful.

Example:

err := InstallVSCodeModules()

if err != nil {
  log.Fatalf("failed to install VS Code modules: %v", err)
}

func ModUpdate

func ModUpdate(recursive bool, v bool) error

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 was not successful.

Example:

recursive := true verbose := true err := ModUpdate(recursive, verbose)

if err != nil {
  log.Fatalf("failed to update modules: %v", err)
}

func Tidy

func Tidy() error

Tidy runs 'go mod tidy' to clean up the module dependencies.

Returns:

error: An error if the Tidy function was not successful.

Example:

err := Tidy()

if err != nil {
  log.Fatalf("failed to tidy modules: %v", err)
}

func UpdateMageDeps

func UpdateMageDeps(magedir string) error

UpdateMageDeps updates the dependencies in a specified Magefile directory. If no directory is provided, it defaults to the 'magefiles' directory.

Parameters:

magedir: A string specifying the path to the magefiles directory.

Returns:

error: An error if the UpdateMageDeps function was not successful.

Example:

magedir := "custom/mage/dir" err := UpdateMageDeps(magedir)

if err != nil {
  log.Fatalf("failed to update Mage dependencies: %v", err)
}

Types

type FuncInfo

type FuncInfo struct {
	// FilePath is the file path of the source file containing the function declaration.
	FilePath string
	// FuncName is the name of the exported function.
	FuncName string
}

FuncInfo contains information about an exported function, including the file path and function name.

func FindExportedFunctionsInPackage

func FindExportedFunctionsInPackage(pkgPath string) ([]FuncInfo, error)

FindExportedFunctionsInPackage finds all exported functions in a given Go package by recursively parsing all non-test Go files in the package directory and returning a slice of FuncInfo structs, each containing 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:

packagePath := "/path/to/your/go/package" funcs, err := 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.Name, f.FilePath)
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL