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 Deprecated string `json:",omitempty"`
26 Error *ModuleError `json:",omitempty"`
27 }
28
29 type ModuleError struct {
30 Err string
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