github.com/gagliardetto/golang-go@v0.0.0-20201020153340-53909ea70814/cmd/go/not-internal/modconv/vyml.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 "strings" 9 10 "golang.org/x/mod/modfile" 11 "golang.org/x/mod/module" 12 ) 13 14 func ParseVendorYML(file string, data []byte) (*modfile.File, error) { 15 mf := new(modfile.File) 16 vendors := false 17 path := "" 18 for _, line := range strings.Split(string(data), "\n") { 19 if line == "" { 20 continue 21 } 22 if strings.HasPrefix(line, "vendors:") { 23 vendors = true 24 } else if line[0] != '-' && line[0] != ' ' && line[0] != '\t' { 25 vendors = false 26 } 27 if !vendors { 28 continue 29 } 30 if strings.HasPrefix(line, "- path:") { 31 path = strings.TrimSpace(line[len("- path:"):]) 32 } 33 if strings.HasPrefix(line, " rev:") { 34 rev := strings.TrimSpace(line[len(" rev:"):]) 35 if path != "" && rev != "" { 36 mf.Require = append(mf.Require, &modfile.Require{Mod: module.Version{Path: path, Version: rev}}) 37 } 38 } 39 } 40 return mf, nil 41 }