Source file src/cmd/go/internal/modconv/glide.go

Documentation: cmd/go/internal/modconv

     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 _, line := range strings.Split(string(data), "\n") {
    19  		if line == "" {
    20  			continue
    21  		}
    22  		if strings.HasPrefix(line, "imports:") {
    23  			imports = true
    24  		} else if line[0] != '-' && line[0] != ' ' && line[0] != '\t' {
    25  			imports = false
    26  		}
    27  		if !imports {
    28  			continue
    29  		}
    30  		if strings.HasPrefix(line, "- name:") {
    31  			name = strings.TrimSpace(line[len("- name:"):])
    32  		}
    33  		if strings.HasPrefix(line, "  version:") {
    34  			version := strings.TrimSpace(line[len("  version:"):])
    35  			if name != "" && version != "" {
    36  				mf.Require = append(mf.Require, &modfile.Require{Mod: module.Version{Path: name, Version: version}})
    37  			}
    38  		}
    39  	}
    40  	return mf, nil
    41  }
    42  

View as plain text