Documentation ¶
Overview ¶
Package golangx provides utility functions for working with Go modules and validating Go project structures. This package includes functions to check if a given path is a Go module, ensuring that the necessary Go module files are present in the specified directory.
The primary function in this package is IsGoModule, which checks if a given path contains a Go module by looking for the presence of a go.mod file.
Example usage:
package main import ( "fmt" "path/to/golangx" ) func main() { err := golangx.IsGoModule("path/to/go/module") if err != nil { fmt.Println(err) } else { fmt.Println("This is a valid Go module.") } }
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func IsGoModule ¶ added in v0.0.14
IsGoModule checks if the given path is a Go module.
Parameters:
- path: The path to check.
Returns:
- An error if the path is not a Go module.
Example:
err := IsGoModule("path/to/go/module") if err != nil { // handle error } // Use err, e.g., fmt.Println(err) // Output: path is not a Go module
func WithGoCgoDisabled ¶
func WithGoCgoDisabled() types.DaggerEnvVars
WithGoCgoDisabled returns a DaggerEnvVars struct that sets the CGO_ENABLED environment variable to "0", disabling CGO for Go builds.
Returns:
- A DaggerEnvVars struct with CGO_ENABLED set to "0".
Example:
envVar := WithGoCgoDisabled() fmt.Println(envVar) // Output: {Name: "CGO_ENABLED", Value: "0", Expand: false}
func WithGoCgoEnabled ¶
func WithGoCgoEnabled() types.DaggerEnvVars
WithGoCgoEnabled returns a DaggerEnvVars struct that sets the CGO_ENABLED environment variable to "1", enabling CGO for Go builds.
Returns:
- A DaggerEnvVars struct with CGO_ENABLED set to "1".
Example:
envVar := WithGoCgoEnabled() fmt.Println(envVar) // Output: {Name: "CGO_ENABLED", Value: "1", Expand: false}
func WithGoPlatform ¶
func WithGoPlatform(platform string) []types.DaggerEnvVars
WithGoPlatform returns a slice of DaggerEnvVars structs that set the GOOS, GOARCH, and optionally GOARM environment variables based on the provided platform string.
Parameters:
- platform: A string representing the target platform in the format "os/arch[/variant]".
Returns:
- A slice of DaggerEnvVars structs with GOOS, GOARCH, and optionally GOARM set.
Example:
envVars := WithGoPlatform("linux/amd64") for _, envVar := range envVars { fmt.Println(envVar) } // Output: // {Name: "GOOS", Value: "linux", Expand: false} // {Name: "GOARCH", Value: "amd64", Expand: false} envVars = WithGoPlatform("linux/arm/v7") for _, envVar := range envVars { fmt.Println(envVar) } // Output: // {Name: "GOOS", Value: "linux", Expand: false} // {Name: "GOARCH", Value: "arm", Expand: false} // {Name: "GOARM", Value: "v7", Expand: false}
Types ¶
This section is empty.