github.com/gagliardetto/golang-go@v0.0.0-20201020153340-53909ea70814/cmd/go/not-internal/modinfo/info.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 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  	Error     *ModuleError  `json:",omitempty"` // error loading module
    25  }
    26  
    27  type ModuleError struct {
    28  	Err string // error text
    29  }
    30  
    31  func (m *ModulePublic) String() string {
    32  	s := m.Path
    33  	if m.Version != "" {
    34  		s += " " + m.Version
    35  		if m.Update != nil {
    36  			s += " [" + m.Update.Version + "]"
    37  		}
    38  	}
    39  	if m.Replace != nil {
    40  		s += " => " + m.Replace.Path
    41  		if m.Replace.Version != "" {
    42  			s += " " + m.Replace.Version
    43  			if m.Replace.Update != nil {
    44  				s += " [" + m.Replace.Update.Version + "]"
    45  			}
    46  		}
    47  	}
    48  	return s
    49  }