...
1
2
3
4
5 package modinfo
6
7 import (
8 "cmd/go/internal/modfetch/codehost"
9 "encoding/json"
10 "time"
11 )
12
13
14
15
16 type ModulePublic struct {
17 Path string `json:",omitempty"`
18 Version string `json:",omitempty"`
19 Query string `json:",omitempty"`
20 Versions []string `json:",omitempty"`
21 Replace *ModulePublic `json:",omitempty"`
22 Time *time.Time `json:",omitempty"`
23 Update *ModulePublic `json:",omitempty"`
24 Main bool `json:",omitempty"`
25 Indirect bool `json:",omitempty"`
26 Dir string `json:",omitempty"`
27 GoMod string `json:",omitempty"`
28 GoVersion string `json:",omitempty"`
29 Retracted []string `json:",omitempty"`
30 Deprecated string `json:",omitempty"`
31 Error *ModuleError `json:",omitempty"`
32 Sum string `json:",omitempty"`
33 GoModSum string `json:",omitempty"`
34 Origin *codehost.Origin `json:",omitempty"`
35 Reuse bool `json:",omitempty"`
36 }
37
38 type ModuleError struct {
39 Err string
40 }
41
42 type moduleErrorNoMethods ModuleError
43
44
45
46
47 func (e *ModuleError) UnmarshalJSON(data []byte) error {
48 if len(data) > 0 && data[0] == '"' {
49 return json.Unmarshal(data, &e.Err)
50 }
51 return json.Unmarshal(data, (*moduleErrorNoMethods)(e))
52 }
53
54 func (m *ModulePublic) String() string {
55 s := m.Path
56 versionString := func(mm *ModulePublic) string {
57 v := mm.Version
58 if len(mm.Retracted) == 0 {
59 return v
60 }
61 return v + " (retracted)"
62 }
63
64 if m.Version != "" {
65 s += " " + versionString(m)
66 if m.Update != nil {
67 s += " [" + versionString(m.Update) + "]"
68 }
69 }
70 if m.Deprecated != "" {
71 s += " (deprecated)"
72 }
73 if m.Replace != nil {
74 s += " => " + m.Replace.Path
75 if m.Replace.Version != "" {
76 s += " " + versionString(m.Replace)
77 if m.Replace.Update != nil {
78 s += " [" + versionString(m.Replace.Update) + "]"
79 }
80 }
81 if m.Replace.Deprecated != "" {
82 s += " (deprecated)"
83 }
84 }
85 return s
86 }
87
View as plain text