terraform-provider-gitea/vendor/github.com/hashicorp/hc-install/internal/build/go_is_installed.go
Malar Invention 00ebcd295e add vendor
2022-04-03 09:37:16 +05:30

29 lines
594 B
Go

package build
import (
"context"
"fmt"
"github.com/hashicorp/go-version"
)
// GoIsInstalled represents a checker of whether Go is installed locally
type GoIsInstalled struct {
RequiredVersion version.Constraints
}
// Check checks whether any Go version is installed locally
func (gii *GoIsInstalled) Check(ctx context.Context) error {
goVersion, err := GetGoVersion(ctx)
if err != nil {
return err
}
if gii.RequiredVersion != nil && !gii.RequiredVersion.Check(goVersion) {
return fmt.Errorf("go %s required (%s available)",
gii.RequiredVersion, goVersion)
}
return nil
}