@@ -22,12 +22,12 @@ import (
22
22
type Package struct {
23
23
Module
24
24
Path string // full import path
25
- PathAfterDirectory string // for display only; used only for directory
26
- Synopsis string
27
- IsRedistributable bool
28
25
URL string // relative to this site
29
26
LatestURL string // link with latest-version placeholder, relative to this site
27
+ IsRedistributable bool
30
28
Licenses []LicenseMetadata
29
+ PathAfterDirectory string // for display on the directories tab; used by Directory
30
+ Synopsis string // for display on the directories tab; used by Directory
31
31
}
32
32
33
33
// Module contains information for an individual module.
@@ -42,18 +42,14 @@ type Module struct {
42
42
Licenses []LicenseMetadata
43
43
}
44
44
45
- // legacyCreatePackage returns a *Package based on the fields of the specified
45
+ // createPackage returns a *Package based on the fields of the specified
46
46
// internal package and version info.
47
47
//
48
48
// latestRequested indicates whether the user requested the latest
49
49
// version of the package. If so, the returned Package.URL will have the
50
50
// structure /<path> instead of /<path>@<version>.
51
- func legacyCreatePackage (pkg * internal.LegacyPackage , mi * internal.ModuleInfo , latestRequested bool ) (_ * Package , err error ) {
52
- defer derrors .Wrap (& err , "legacyCreatePackage(%v, %v)" , pkg , mi )
53
-
54
- if pkg == nil || mi == nil {
55
- return nil , fmt .Errorf ("package and version info must not be nil" )
56
- }
51
+ func createPackage (pkg * internal.PackageMeta , mi * internal.ModuleInfo , latestRequested bool ) (_ * Package , err error ) {
52
+ defer derrors .Wrap (& err , "createPackage(%v, %v, %t)" , pkg , mi , latestRequested )
57
53
58
54
var modLicenses []* licenses.Metadata
59
55
for _ , lm := range pkg .Licenses {
@@ -69,48 +65,12 @@ func legacyCreatePackage(pkg *internal.LegacyPackage, mi *internal.ModuleInfo, l
69
65
}
70
66
return & Package {
71
67
Path : pkg .Path ,
72
- Synopsis : pkg .Synopsis ,
73
68
IsRedistributable : pkg .IsRedistributable ,
74
69
Licenses : transformLicenseMetadata (pkg .Licenses ),
75
70
Module : * m ,
76
71
URL : constructPackageURL (pkg .Path , mi .ModulePath , urlVersion ),
77
72
LatestURL : constructPackageURL (pkg .Path , mi .ModulePath , middleware .LatestVersionPlaceholder ),
78
- }, nil
79
- }
80
-
81
- // createPackageNew returns a *Package based on the fields of the specified
82
- // internal package and version info.
83
- //
84
- // latestRequested indicates whether the user requested the latest
85
- // version of the package. If so, the returned Package.URL will have the
86
- // structure /<path> instead of /<path>@<version>.
87
- func createPackageNew (vdir * internal.VersionedDirectory , latestRequested bool ) (_ * Package , err error ) {
88
- defer derrors .Wrap (& err , "createPackageNew(%v, %t)" , vdir , latestRequested )
89
-
90
- if vdir == nil || vdir .Package == nil {
91
- return nil , fmt .Errorf ("package info must not be nil" )
92
- }
93
-
94
- var modLicenses []* licenses.Metadata
95
- for _ , lm := range vdir .Licenses {
96
- if path .Dir (lm .FilePath ) == "." {
97
- modLicenses = append (modLicenses , lm )
98
- }
99
- }
100
-
101
- m := createModule (& vdir .ModuleInfo , modLicenses , latestRequested )
102
- urlVersion := m .LinkVersion
103
- if latestRequested {
104
- urlVersion = internal .LatestVersion
105
- }
106
- return & Package {
107
- Path : vdir .Path ,
108
- Synopsis : vdir .Package .Documentation .Synopsis ,
109
- IsRedistributable : vdir .DirectoryNew .IsRedistributable ,
110
- Licenses : transformLicenseMetadata (vdir .Licenses ),
111
- Module : * m ,
112
- URL : constructPackageURL (vdir .Path , vdir .ModulePath , urlVersion ),
113
- LatestURL : constructPackageURL (vdir .Path , vdir .ModulePath , middleware .LatestVersionPlaceholder ),
73
+ Synopsis : pkg .Synopsis ,
114
74
}, nil
115
75
}
116
76
@@ -160,15 +120,15 @@ func constructPackageURL(pkgPath, modulePath, linkVersion string) string {
160
120
}
161
121
162
122
// effectiveName returns either the command name or package name.
163
- func effectiveName (pkg * internal. LegacyPackage ) string {
164
- if pkg . Name != "main" {
165
- return pkg . Name
123
+ func effectiveName (pkgPath , pkgName string ) string {
124
+ if pkgName != "main" {
125
+ return pkgName
166
126
}
167
127
var prefix string // package path without version
168
- if pkg . Path [len (pkg . Path )- 3 :] == "/v1" {
169
- prefix = pkg . Path [:len (pkg . Path )- 3 ]
128
+ if pkgPath [len (pkgPath )- 3 :] == "/v1" {
129
+ prefix = pkgPath [:len (pkgPath )- 3 ]
170
130
} else {
171
- prefix , _ , _ = module .SplitPathVersion (pkg . Path )
131
+ prefix , _ , _ = module .SplitPathVersion (pkgPath )
172
132
}
173
133
_ , base := path .Split (prefix )
174
134
return base
@@ -196,7 +156,7 @@ func packageHTMLTitle(pkg *internal.LegacyPackage) string {
196
156
if pkg .Name != "main" {
197
157
return pkg .Name + " package"
198
158
}
199
- return effectiveName (pkg ) + " command"
159
+ return effectiveName (pkg . Path , pkg . Name ) + " command"
200
160
}
201
161
202
162
// packageHTMLTitleNew constructs the details page title for pkg.
@@ -215,7 +175,7 @@ func packageTitle(pkg *internal.LegacyPackage) string {
215
175
if pkg .Name != "main" {
216
176
return "package " + pkg .Name
217
177
}
218
- return "command " + effectiveName (pkg )
178
+ return "command " + effectiveName (pkg . Path , pkg . Name )
219
179
}
220
180
221
181
// packageTitleNew returns the package title as it will
0 commit comments