github.com/bir3/gocompiler@v0.3.205/src/cmd/gocmd/internal/modconv/godeps.go (about) 1 // Copyright 2018 The Go Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style 3 // license that can be found in the LICENSE file. 4 5 package modconv 6 7 import ( 8 "encoding/json" 9 10 "github.com/bir3/gocompiler/src/xvendor/golang.org/x/mod/modfile" 11 "github.com/bir3/gocompiler/src/xvendor/golang.org/x/mod/module" 12 ) 13 14 func ParseGodepsJSON(file string, data []byte) (*modfile.File, error) { 15 var cfg struct { 16 ImportPath string 17 Deps []struct { 18 ImportPath string 19 Rev string 20 } 21 } 22 if err := json.Unmarshal(data, &cfg); err != nil { 23 return nil, err 24 } 25 mf := new(modfile.File) 26 for _, d := range cfg.Deps { 27 mf.Require = append(mf.Require, &modfile.Require{Mod: module.Version{Path: d.ImportPath, Version: d.Rev}}) 28 } 29 return mf, nil 30 }