Source File
404.go
Belonging Package
golang.org/x/pkgsite/internal/frontend
package frontend
import (
)
var errUnitNotFoundWithoutFetch = &serverError{
status: http.StatusNotFound,
epage: &errorPage{
messageTemplate: template.MakeTrustedTemplate(`
<h3 class="Error-message">{{.StatusText}}</h3>
<p class="Error-message">Check that you entered the URL correctly or try fetching it following the
<a href="/about#adding-a-package">instructions here</a>.</p>`),
MessageData: struct{ StatusText string }{http.StatusText(http.StatusNotFound)},
},
}
func ( *Server) ( http.ResponseWriter, *http.Request,
internal.DataSource, , , string) ( error) {
defer derrors.Wrap(&, "servePathNotFoundPage(w, r, %q, %q)", , )
, := .(*postgres.DB)
if ! {
return proxydatasourceNotSupportedErr()
}
:= .Context()
if stdlib.Contains() {
var string
, = stdlibPathForShortcut(, , )
log.Error(, )
}
if != "" {
http.Redirect(, , fmt.Sprintf("/%s", ), http.StatusFound)
return
}
return &serverError{status: http.StatusNotFound}
}
, := previousFetchStatusAndResponse(, , , , )
switch .status {
case http.StatusFound, derrors.ToStatus(derrors.AlternativeModule):
return errUnitNotFoundWithoutFetch
}
, := .GetVersionMap(, .goModPath, internal.LatestVersion)
if ( != nil && !errors.Is(, derrors.NotFound)) ||
return errUnitNotFoundWithoutFetch
}
:= constructUnitURL(.goModPath, .goModPath, internal.LatestVersion)
cookie.Set(, cookie.AlternativeModuleFlash, , )
http.Redirect(, , , http.StatusFound)
return nil
case http.StatusInternalServerError:
return pathNotFoundError(, )
default:
if := githubPathRedirect(); != "" {
http.Redirect(, , , http.StatusFound)
return
}
if .status == http.StatusNotFound && time.Since(.updatedAt) > .taskIDChangeInterval {
return pathNotFoundError(, )
}
, := .GetNestedModules(, )
if == nil && len() > 0 {
http.Redirect(, , "/search?q="+url.QueryEscape(), http.StatusFound)
return nil
}
return &serverError{
status: .status,
epage: &errorPage{
messageTemplate: uncheckedconversions.TrustedTemplateFromStringKnownToSatisfyTypeContract(`
<h3 class="Error-message">{{.StatusText}}</h3>
<p class="Error-message">` + html.UnescapeString(.responseText) + `</p>`),
MessageData: struct{ string }{http.StatusText(.status)},
},
}
}
}
var githubRegexp = regexp.MustCompile(`(blob|tree)(/[^/]+)?`)
func ( string) string {
:= strings.Split(, "/")
if len() <= 3 || [0] != "github.com" {
return ""
}
:= strings.Split(, "/"+githubRegexp.FindString())
if len() != 2 {
return ""
}
:= [0]
if [1] != "" {
= [0] + [1]
}
return constructUnitURL(, , internal.LatestVersion)
}
func (, string) error {
if !isSupportedVersion(, ) {
return invalidVersionError(, )
}
if stdlib.Contains() {
return &serverError{status: http.StatusNotFound}
}
:=
if != internal.LatestVersion {
= fmt.Sprintf("%s@%s", , )
}
return &serverError{
status: http.StatusNotFound,
epage: &errorPage{
templateName: "fetch.tmpl",
MessageData: ,
},
}
}
, := modulePathsToFetch(, , , )
if != nil {
return nil,
, := .GetVersionMap(, [0], )
if != nil {
return nil,
if != nil &&
(.Status >= 500 ||
.Status == derrors.ToStatus(derrors.AlternativeModule) ||
.Status == derrors.ToStatus(derrors.BadModule)) {
return resultFromFetchRequest([]*fetchResult{
{
modulePath: .ModulePath,
goModPath: .GoModPath,
status: .Status,
err: errors.New(.Error),
},
}, , )
}
, , := .GetLatestMajorPathForV1Path(, )
if != nil && != derrors.NotFound {
return nil,
}
if != && != 1 && != "" {
return &fetchResult{
modulePath: ,
goModPath: ,
status: http.StatusFound,
}, nil
}
, := .GetVersionMaps(, , )
if != nil {
return nil,
}
var []*fetchResult
for , := range {
:= fetchResultFromVersionMap()
= append(, )
if .Status == http.StatusOK || .Status == 290 {
.err = errPathDoesNotExistInModule
}
}
if len() == 0 {
return nil, derrors.NotFound
}
return resultFromFetchRequest(, , )
}
func ( *internal.VersionMap) *fetchResult {
var error
if .Error != "" {
= errors.New(.Error)
}
return &fetchResult{
modulePath: .ModulePath,
goModPath: .GoModPath,
status: .Status,
updatedAt: .UpdatedAt,
err: ,
}
![]() |
The pages are generated with Golds v0.3.2-preview. (GOOS=darwin GOARCH=amd64) Golds is a Go 101 project developed by Tapir Liu. PR and bug reports are welcome and can be submitted to the issue list. Please follow @Go100and1 (reachable from the left QR code) to get the latest news of Golds. |