mirror of
https://github.com/tweag/gomod2nix.git
synced 2024-11-09 20:19:08 +00:00
34 lines
613 B
Go
34 lines
613 B
Go
package fetch
|
|
|
|
import (
|
|
"bytes"
|
|
"fmt"
|
|
"io/ioutil"
|
|
"strings"
|
|
)
|
|
|
|
func parseGoSum(file string) (map[string]string, error) {
|
|
|
|
// Read go.mod
|
|
data, err := ioutil.ReadFile(file)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
pkgs := make(map[string]string) // goPackagepath -> rev
|
|
for lineno, line := range bytes.Split(data, []byte("\n")) {
|
|
if len(line) == 0 {
|
|
continue
|
|
}
|
|
|
|
f := strings.Fields(string(line))
|
|
if len(f) != 3 {
|
|
return nil, fmt.Errorf("malformed go.sum:\n%s:%d: wrong number of fields %v", file, lineno, len(f))
|
|
}
|
|
|
|
pkgs[f[0]] = strings.TrimSuffix(f[1], "/go.mod")
|
|
}
|
|
|
|
return pkgs, nil
|
|
|
|
}
|