internal/frontend: rename legacy functions

Functions that are used only by the legacy data model are renamed with the prefix legacy.

This includes:

* createPackage
* createDirectory
* servePackagePage
* serveModulePage
* serveDirectoryPage

Change-Id: I72071f56df7e79dfbf27355479d29bad4ad19a38
Reviewed-on: https://go-review.googlesource.com/c/pkgsite/+/238097
Reviewed-by: Jonathan Amsterdam <jba@google.com>
This commit is contained in:
Julie Qiu 2020-06-15 21:07:16 -04:00
Родитель b26ac09579
Коммит 9993c78261
8 изменённых файлов: 32 добавлений и 32 удалений

Просмотреть файл

@ -106,12 +106,12 @@ func (s *Server) serveDetails(w http.ResponseWriter, r *http.Request) (err error
}
// Depending on what the request was for, return the module or package page.
if isModule || fullPath == stdlib.ModulePath {
return s.serveModulePage(w, r, fullPath, requestedVersion)
return s.legacyServeModulePage(w, r, fullPath, requestedVersion)
}
if isActiveUseDirectories(ctx) {
return s.servePackagePageNew(w, r, fullPath, modulePath, requestedVersion)
}
return s.servePackagePage(w, r, fullPath, modulePath, requestedVersion)
return s.legacyServePackagePage(w, r, fullPath, modulePath, requestedVersion)
}
// parseDetailsURLPath parses a URL path that refers (or may refer) to something

Просмотреть файл

@ -34,8 +34,8 @@ type Directory struct {
URL string
}
func (s *Server) serveDirectoryPage(ctx context.Context, w http.ResponseWriter, r *http.Request, dbDir *internal.LegacyDirectory, requestedVersion string) (err error) {
defer derrors.Wrap(&err, "serveDirectoryPage for %s@%s", dbDir.Path, requestedVersion)
func (s *Server) legacyServeDirectoryPage(ctx context.Context, w http.ResponseWriter, r *http.Request, dbDir *internal.LegacyDirectory, requestedVersion string) (err error) {
defer derrors.Wrap(&err, "legacyServeDirectoryPage for %s@%s", dbDir.Path, requestedVersion)
tab := r.FormValue("tab")
settings, ok := directoryTabLookup[tab]
if tab == "" || !ok || settings.Disabled {
@ -46,7 +46,7 @@ func (s *Server) serveDirectoryPage(ctx context.Context, w http.ResponseWriter,
if err != nil {
return err
}
header, err := createDirectory(dbDir, licensesToMetadatas(licenses), false)
header, err := legacyCreateDirectory(dbDir, licensesToMetadatas(licenses), false)
if err != nil {
return err
}
@ -96,7 +96,7 @@ func fetchDirectoryDetails(ctx context.Context, ds internal.DataSource, dirPath
if err != nil {
return nil, err
}
return createDirectory(&internal.LegacyDirectory{
return legacyCreateDirectory(&internal.LegacyDirectory{
LegacyModuleInfo: internal.LegacyModuleInfo{ModuleInfo: *mi},
Path: dirPath,
Packages: pkgs,
@ -105,7 +105,7 @@ func fetchDirectoryDetails(ctx context.Context, ds internal.DataSource, dirPath
dbDir, err := ds.LegacyGetDirectory(ctx, dirPath, mi.ModulePath, mi.Version, internal.AllFields)
if errors.Is(err, derrors.NotFound) {
return createDirectory(&internal.LegacyDirectory{
return legacyCreateDirectory(&internal.LegacyDirectory{
LegacyModuleInfo: internal.LegacyModuleInfo{ModuleInfo: *mi},
Path: dirPath,
Packages: nil,
@ -114,10 +114,10 @@ func fetchDirectoryDetails(ctx context.Context, ds internal.DataSource, dirPath
if err != nil {
return nil, err
}
return createDirectory(dbDir, licmetas, includeDirPath)
return legacyCreateDirectory(dbDir, licmetas, includeDirPath)
}
// createDirectory constructs a *LegacyDirectory from the provided dbDir and licmetas.
// legacyCreateDirectory constructs a *LegacyDirectory from the provided dbDir and licmetas.
//
// includeDirPath indicates whether a package is included if its import path is
// the same as dirPath.
@ -126,15 +126,15 @@ func fetchDirectoryDetails(ctx context.Context, ds internal.DataSource, dirPath
// the module path. However, on the package and directory view's
// "Subdirectories" tab, we do not want to include packages whose import paths
// are the same as the dirPath.
func createDirectory(dbDir *internal.LegacyDirectory, licmetas []*licenses.Metadata, includeDirPath bool) (_ *Directory, err error) {
defer derrors.Wrap(&err, "createDirectory(%q, %q, %t)", dbDir.Path, dbDir.Version, includeDirPath)
func legacyCreateDirectory(dbDir *internal.LegacyDirectory, licmetas []*licenses.Metadata, includeDirPath bool) (_ *Directory, err error) {
defer derrors.Wrap(&err, "legacyCreateDirectory(%q, %q, %t)", dbDir.Path, dbDir.Version, includeDirPath)
var packages []*Package
for _, pkg := range dbDir.Packages {
if !includeDirPath && pkg.Path == dbDir.Path {
continue
}
newPkg, err := createPackage(pkg, &dbDir.ModuleInfo, false)
newPkg, err := legacyCreatePackage(pkg, &dbDir.ModuleInfo, false)
if err != nil {
return nil, err
}

Просмотреть файл

@ -33,7 +33,7 @@ func TestFetchDirectoryDetails(t *testing.T) {
var wantPkgs []*Package
for _, suffix := range suffixes {
sp := sample.LegacyPackage(modulePath, suffix)
pkg, err := createPackage(sp, mi, false)
pkg, err := legacyCreatePackage(sp, mi, false)
if err != nil {
t.Fatal(err)
}

Просмотреть файл

@ -43,14 +43,14 @@ type Module struct {
Licenses []LicenseMetadata
}
// createPackage returns a *Package based on the fields of the specified
// legacyCreatePackage returns a *Package based on the fields of the specified
// internal package and version info.
//
// latestRequested indicates whether the user requested the latest
// version of the package. If so, the returned Package.URL will have the
// structure /<path> instead of /<path>@<version>.
func createPackage(pkg *internal.LegacyPackage, mi *internal.ModuleInfo, latestRequested bool) (_ *Package, err error) {
defer derrors.Wrap(&err, "createPackage(%v, %v)", pkg, mi)
func legacyCreatePackage(pkg *internal.LegacyPackage, mi *internal.ModuleInfo, latestRequested bool) (_ *Package, err error) {
defer derrors.Wrap(&err, "legacyCreatePackage(%v, %v)", pkg, mi)
if pkg == nil || mi == nil {
return nil, fmt.Errorf("package and version info must not be nil")

Просмотреть файл

@ -138,12 +138,12 @@ func TestCreatePackageHeader(t *testing.T) {
},
} {
t.Run(tc.label, func(t *testing.T) {
got, err := createPackage(&tc.pkg.LegacyPackage, &tc.pkg.ModuleInfo, false)
got, err := legacyCreatePackage(&tc.pkg.LegacyPackage, &tc.pkg.ModuleInfo, false)
if err != nil {
t.Fatal(err)
}
if diff := cmp.Diff(tc.wantPkg, got); diff != "" {
t.Errorf("createPackage(%v) mismatch (-want +got):\n%s", tc.pkg, diff)
t.Errorf("legacyCreatePackage(%v) mismatch (-want +got):\n%s", tc.pkg, diff)
}
})
}

Просмотреть файл

@ -15,9 +15,9 @@ import (
"golang.org/x/pkgsite/internal/log"
)
// serveModulePage serves details pages for the module specified by modulePath
// legacyServeModulePage serves details pages for the module specified by modulePath
// and version.
func (s *Server) serveModulePage(w http.ResponseWriter, r *http.Request, modulePath, requestedVersion string) error {
func (s *Server) legacyServeModulePage(w http.ResponseWriter, r *http.Request, modulePath, requestedVersion string) error {
// This function handles top level behavior related to the existence of the
// requested modulePath@version:
// TODO: fix
@ -31,7 +31,7 @@ func (s *Server) serveModulePage(w http.ResponseWriter, r *http.Request, moduleP
ctx := r.Context()
mi, err := s.ds.GetModuleInfo(ctx, modulePath, requestedVersion)
if err == nil {
return s.serveModulePageWithModule(ctx, w, r, mi, requestedVersion)
return s.legacyServeModulePageWithModule(ctx, w, r, mi, requestedVersion)
}
if !errors.Is(err, derrors.NotFound) {
return err
@ -48,7 +48,7 @@ func (s *Server) serveModulePage(w http.ResponseWriter, r *http.Request, moduleP
return pathNotFoundError(ctx, "module", modulePath, requestedVersion)
}
func (s *Server) serveModulePageWithModule(ctx context.Context, w http.ResponseWriter, r *http.Request, mi *internal.LegacyModuleInfo, requestedVersion string) error {
func (s *Server) legacyServeModulePageWithModule(ctx context.Context, w http.ResponseWriter, r *http.Request, mi *internal.LegacyModuleInfo, requestedVersion string) error {
licenses, err := s.ds.LegacyGetModuleLicenses(ctx, mi.ModulePath, mi.Version)
if err != nil {
return err

Просмотреть файл

@ -24,9 +24,9 @@ func (s *Server) handlePackageDetailsRedirect(w http.ResponseWriter, r *http.Req
http.Redirect(w, r, urlPath, http.StatusMovedPermanently)
}
// servePackagePage serves details pages for the package with import path
// legacyServePackagePage serves details pages for the package with import path
// pkgPath, in the module specified by modulePath and version.
func (s *Server) servePackagePage(w http.ResponseWriter, r *http.Request, pkgPath, modulePath, version string) (err error) {
func (s *Server) legacyServePackagePage(w http.ResponseWriter, r *http.Request, pkgPath, modulePath, version string) (err error) {
ctx := r.Context()
// This function handles top level behavior related to the existence of the
@ -38,7 +38,7 @@ func (s *Server) servePackagePage(w http.ResponseWriter, r *http.Request, pkgPat
// 4. Just serve a 404
pkg, err := s.ds.LegacyGetPackage(ctx, pkgPath, modulePath, version)
if err == nil {
return s.servePackagePageWithPackage(ctx, w, r, pkg, version)
return s.legacyServePackagePageWithPackage(ctx, w, r, pkg, version)
}
if !errors.Is(err, derrors.NotFound) {
return err
@ -54,11 +54,11 @@ func (s *Server) servePackagePage(w http.ResponseWriter, r *http.Request, pkgPat
}
return err
}
return s.serveDirectoryPage(ctx, w, r, dbDir, version)
return s.legacyServeDirectoryPage(ctx, w, r, dbDir, version)
}
dir, err := s.ds.LegacyGetDirectory(ctx, pkgPath, modulePath, version, internal.AllFields)
if err == nil {
return s.serveDirectoryPage(ctx, w, r, dir, version)
return s.legacyServeDirectoryPage(ctx, w, r, dir, version)
}
if !errors.Is(err, derrors.NotFound) {
// The only error we expect is NotFound, so serve an 500 here, otherwise
@ -82,13 +82,13 @@ func (s *Server) servePackagePage(w http.ResponseWriter, r *http.Request, pkgPat
return pathNotFoundError(ctx, "package", pkgPath, version)
}
func (s *Server) servePackagePageWithPackage(ctx context.Context, w http.ResponseWriter, r *http.Request, pkg *internal.LegacyVersionedPackage, requestedVersion string) (err error) {
func (s *Server) legacyServePackagePageWithPackage(ctx context.Context, w http.ResponseWriter, r *http.Request, pkg *internal.LegacyVersionedPackage, requestedVersion string) (err error) {
defer func() {
if _, ok := err.(*serverError); !ok {
derrors.Wrap(&err, "servePackagePageWithPackage(w, r, %q, %q, %q)", pkg.Path, pkg.ModulePath, requestedVersion)
derrors.Wrap(&err, "legacyServePackagePageWithPackage(w, r, %q, %q, %q)", pkg.Path, pkg.ModulePath, requestedVersion)
}
}()
pkgHeader, err := createPackage(&pkg.LegacyPackage, &pkg.ModuleInfo, requestedVersion == internal.LatestVersion)
pkgHeader, err := legacyCreatePackage(&pkg.LegacyPackage, &pkg.ModuleInfo, requestedVersion == internal.LatestVersion)
if err != nil {
return fmt.Errorf("creating package header for %s@%s: %v", pkg.Path, pkg.Version, err)
}
@ -181,7 +181,7 @@ func (s *Server) servePackagePageNew(w http.ResponseWriter, r *http.Request, ful
if err != nil {
return err
}
return s.serveDirectoryPage(ctx, w, r, dir, inVersion)
return s.legacyServeDirectoryPage(ctx, w, r, dir, inVersion)
}
// stdlibPathForShortcut returns a path in the stdlib that shortcut should redirect to,

Просмотреть файл

@ -230,7 +230,7 @@ func constructDetailsForDirectory(r *http.Request, tab string, dir *internal.Leg
// fetchDetailsForPackage. However, since we already have the directory
// and licenses info, it doesn't make sense to call
// postgres.GetDirectory again.
return createDirectory(dir, licensesToMetadatas(licenses), false)
return legacyCreateDirectory(dir, licensesToMetadatas(licenses), false)
case "licenses":
return &LicensesDetails{Licenses: transformLicenses(dir.ModulePath, dir.Version, licenses)}, nil
}