Black Lives Matter. Support the Equal Justice Initiative.

Source file src/cmd/go/internal/modinfo/info.go

Documentation: cmd/go/internal/modinfo

     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 modinfo
     6  
     7  import "time"
     8  
     9  // Note that these structs are publicly visible (part of go list's API)
    10  // and the fields are documented in the help text in ../list/list.go
    11  
    12  type ModulePublic struct {
    13  	Path      string        `json:",omitempty"` // module path
    14  	Version   string        `json:",omitempty"` // module version
    15  	Versions  []string      `json:",omitempty"` // available module versions
    16  	Replace   *ModulePublic `json:",omitempty"` // replaced by this module
    17  	Time      *time.Time    `json:",omitempty"` // time version was created
    18  	Update    *ModulePublic `json:",omitempty"` // available update (with -u)
    19  	Main      bool          `json:",omitempty"` // is this the main module?
    20  	Indirect  bool          `json:",omitempty"` // module is only indirectly needed by main module
    21  	Dir       string        `json:",omitempty"` // directory holding local copy of files, if any
    22  	GoMod     string        `json:",omitempty"` // path to go.mod file describing module, if any
    23  	GoVersion string        `json:",omitempty"` // go version used in module
    24  	Retracted []string      `json:",omitempty"` // retraction information, if any (with -retracted or -u)
    25  	Error     *ModuleError  `json:",omitempty"` // error loading module
    26  }
    27  
    28  type ModuleError struct {
    29  	Err string // error text
    30  }
    31  
    32  func (m *ModulePublic) String() string {
    33  	s := m.Path
    34  	versionString := func(mm *ModulePublic) string {
    35  		v := mm.Version
    36  		if len(mm.Retracted) == 0 {
    37  			return v
    38  		}
    39  		return v + " (retracted)"
    40  	}
    41  
    42  	if m.Version != "" {
    43  		s += " " + versionString(m)
    44  		if m.Update != nil {
    45  			s += " [" + versionString(m.Update) + "]"
    46  		}
    47  	}
    48  	if m.Replace != nil {
    49  		s += " => " + m.Replace.Path
    50  		if m.Replace.Version != "" {
    51  			s += " " + versionString(m.Replace)
    52  			if m.Replace.Update != nil {
    53  				s += " [" + versionString(m.Replace.Update) + "]"
    54  			}
    55  		}
    56  	}
    57  	return s
    58  }
    59  

View as plain text