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  	Deprecated string        `json:",omitempty"` // deprecation message, if any (with -u)
    26  	Error      *ModuleError  `json:",omitempty"` // error loading module
    27  }
    28  
    29  type ModuleError struct {
    30  	Err string // error text
    31  }
    32  
    33  func (m *ModulePublic) String() string {
    34  	s := m.Path
    35  	versionString := func(mm *ModulePublic) string {
    36  		v := mm.Version
    37  		if len(mm.Retracted) == 0 {
    38  			return v
    39  		}
    40  		return v + " (retracted)"
    41  	}
    42  
    43  	if m.Version != "" {
    44  		s += " " + versionString(m)
    45  		if m.Update != nil {
    46  			s += " [" + versionString(m.Update) + "]"
    47  		}
    48  	}
    49  	if m.Deprecated != "" {
    50  		s += " (deprecated)"
    51  	}
    52  	if m.Replace != nil {
    53  		s += " => " + m.Replace.Path
    54  		if m.Replace.Version != "" {
    55  			s += " " + versionString(m.Replace)
    56  			if m.Replace.Update != nil {
    57  				s += " [" + versionString(m.Replace.Update) + "]"
    58  			}
    59  		}
    60  		if m.Replace.Deprecated != "" {
    61  			s += " (deprecated)"
    62  		}
    63  	}
    64  	return s
    65  }
    66  

View as plain text