github.com/megatontech/mynoteforgo@v0.0.0-20200507084910-5d0c6ea6e890/源码/cmd/go/internal/modconv/glide.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 "cmd/go/internal/modfile" 11 "cmd/go/internal/module" 12 ) 13 14 func ParseGlideLock(file string, data []byte) (*modfile.File, error) { 15 mf := new(modfile.File) 16 imports := false 17 name := "" 18 for lineno, line := range strings.Split(string(data), "\n") { 19 lineno++ 20 if line == "" { 21 continue 22 } 23 if strings.HasPrefix(line, "imports:") { 24 imports = true 25 } else if line[0] != '-' && line[0] != ' ' && line[0] != '\t' { 26 imports = false 27 } 28 if !imports { 29 continue 30 } 31 if strings.HasPrefix(line, "- name:") { 32 name = strings.TrimSpace(line[len("- name:"):]) 33 } 34 if strings.HasPrefix(line, " version:") { 35 version := strings.TrimSpace(line[len(" version:"):]) 36 if name != "" && version != "" { 37 mf.Require = append(mf.Require, &modfile.Require{Mod: module.Version{Path: name, Version: version}}) 38 } 39 } 40 } 41 return mf, nil 42 }