зеркало из https://github.com/golang/pkgsite.git
internal/frontend: add isSupportedVersion
isSupportedVersion is added. master is now a supported version if the feature flag ExperimentFrontendPackageAtMaster is on. Updates golang/go#36811 Change-Id: Ib1c885a5e75cb697b8e99fd8e8c9a347e2b344ed Reviewed-on: https://team-review.git.corp.google.com/c/golang/discovery/+/753605 CI-Result: Cloud Build <devtools-proctor-result-processor@system.gserviceaccount.com> Reviewed-by: Jonathan Amsterdam <jba@google.com>
This commit is contained in:
Родитель
45475dd537
Коммит
046b3fe7ab
|
@ -10,6 +10,7 @@ import (
|
|||
|
||||
const (
|
||||
ExperimentFrontendFetch = "frontend-fetch"
|
||||
ExperimentFrontendPackageAtMaster = "frontend-package-at-master"
|
||||
ExperimentInsertDirectories = "insert-directories"
|
||||
ExperimentInsertPlaygroundLinks = "insert-playground-links"
|
||||
ExperimentInsertSerializable = "insert-serializable-txn"
|
||||
|
|
|
@ -15,6 +15,7 @@ import (
|
|||
"golang.org/x/mod/semver"
|
||||
"golang.org/x/pkgsite/internal"
|
||||
"golang.org/x/pkgsite/internal/derrors"
|
||||
"golang.org/x/pkgsite/internal/experiment"
|
||||
"golang.org/x/pkgsite/internal/stdlib"
|
||||
)
|
||||
|
||||
|
@ -128,7 +129,7 @@ func parseDetailsURLPath(urlPath string) (fullPath, modulePath, version string,
|
|||
// checkPathAndVersion verifies that the requested path and version are
|
||||
// acceptable. The given path may be a module or package path.
|
||||
func checkPathAndVersion(ctx context.Context, ds internal.DataSource, path, version string) error {
|
||||
if version != internal.LatestVersion && !semver.IsValid(version) {
|
||||
if !isSupportedVersion(ctx, version) {
|
||||
return &serverError{
|
||||
status: http.StatusBadRequest,
|
||||
epage: &errorPage{
|
||||
|
@ -148,6 +149,24 @@ func checkPathAndVersion(ctx context.Context, ds internal.DataSource, path, vers
|
|||
return nil
|
||||
}
|
||||
|
||||
// isSupportedVersion reports whether the version is supported by the frontend.
|
||||
func isSupportedVersion(ctx context.Context, version string) bool {
|
||||
if version == internal.LatestVersion || semver.IsValid(version) {
|
||||
return true
|
||||
}
|
||||
if isActivePathAtMaster(ctx) {
|
||||
return version == internal.MasterVersion
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func isActivePathAtMaster(ctx context.Context) bool {
|
||||
return experiment.IsActive(ctx, internal.ExperimentFrontendPackageAtMaster) &&
|
||||
experiment.IsActive(ctx, internal.ExperimentFrontendFetch) &&
|
||||
experiment.IsActive(ctx, internal.ExperimentInsertDirectories) &&
|
||||
experiment.IsActive(ctx, internal.ExperimentUseDirectories)
|
||||
}
|
||||
|
||||
// pathNotFoundError returns an error page with instructions on how to
|
||||
// add a package or module to the site. pathType is always either the string
|
||||
// "package" or "module".
|
||||
|
|
Загрузка…
Ссылка в новой задаче