aboutsummaryrefslogtreecommitdiffstats
path: root/vendor/github.com/ldez/gomoddirectives/module.go
diff options
context:
space:
mode:
authorTaras Madan <tarasmadan@google.com>2025-01-22 16:07:17 +0100
committerTaras Madan <tarasmadan@google.com>2025-01-23 10:42:36 +0000
commit7b4377ad9d8a7205416df8d6217ef2b010f89481 (patch)
treee6fec4fd12ff807a16d847923f501075bf71d16c /vendor/github.com/ldez/gomoddirectives/module.go
parent475a4c203afb8b7d3af51c4fd32bb170ff32a45e (diff)
vendor: delete
Diffstat (limited to 'vendor/github.com/ldez/gomoddirectives/module.go')
-rw-r--r--vendor/github.com/ldez/gomoddirectives/module.go48
1 files changed, 0 insertions, 48 deletions
diff --git a/vendor/github.com/ldez/gomoddirectives/module.go b/vendor/github.com/ldez/gomoddirectives/module.go
deleted file mode 100644
index 4cb365379..000000000
--- a/vendor/github.com/ldez/gomoddirectives/module.go
+++ /dev/null
@@ -1,48 +0,0 @@
-package gomoddirectives
-
-import (
- "bytes"
- "encoding/json"
- "errors"
- "fmt"
- "os"
- "os/exec"
-
- "golang.org/x/mod/modfile"
-)
-
-type modInfo struct {
- Path string `json:"Path"`
- Dir string `json:"Dir"`
- GoMod string `json:"GoMod"`
- GoVersion string `json:"GoVersion"`
- Main bool `json:"Main"`
-}
-
-// GetModuleFile gets module file.
-func GetModuleFile() (*modfile.File, error) {
- // https://github.com/golang/go/issues/44753#issuecomment-790089020
- cmd := exec.Command("go", "list", "-m", "-json")
-
- raw, err := cmd.Output()
- if err != nil {
- return nil, fmt.Errorf("command go list: %w: %s", err, string(raw))
- }
-
- var v modInfo
- err = json.NewDecoder(bytes.NewBuffer(raw)).Decode(&v)
- if err != nil {
- return nil, fmt.Errorf("unmarshaling error: %w: %s", err, string(raw))
- }
-
- if v.GoMod == "" {
- return nil, errors.New("working directory is not part of a module")
- }
-
- raw, err = os.ReadFile(v.GoMod)
- if err != nil {
- return nil, fmt.Errorf("reading go.mod file: %w", err)
- }
-
- return modfile.Parse("go.mod", raw, nil)
-}