1
2
3
4
5 package modinfo
6
7 import "time"
8
9
10
11
12 type ModulePublic struct {
13 Path string `json:",omitempty"`
14 Version string `json:",omitempty"`
15 Versions []string `json:",omitempty"`
16 Replace *ModulePublic `json:",omitempty"`
17 Time *time.Time `json:",omitempty"`
18 Update *ModulePublic `json:",omitempty"`
19 Main bool `json:",omitempty"`
20 Indirect bool `json:",omitempty"`
21 Dir string `json:",omitempty"`
22 GoMod string `json:",omitempty"`
23 GoVersion string `json:",omitempty"`
24 Retracted []string `json:",omitempty"`
25 Error *ModuleError `json:",omitempty"`
26 }
27
28 type ModuleError struct {
29 Err string
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