Source File
load.go
Belonging Package
golang.org/x/pkgsite/internal/fetch
package fetch
import (
)
type BadPackageError struct {
Err error // Not nil.
}
func ( *BadPackageError) () string { return .Err.Error() }
:= make(map[string][]byte)
for , := range {
, := path.Split(.Name)
, := readZipFile(, MaxFileSize)
if != nil {
return nil,
}
[] =
}
:= .ModulePath
:= path.Join(, )
if == stdlib.ModulePath {
=
}
:= internal.V1Path(, )
:= map[string]*internal.Documentation{}
for , := range internal.BuildContexts {
, := matchingFiles(.GOOS, .GOARCH, )
if != nil {
return nil,
}
:= mapKeyForFiles()
:= *
.GOOS = .GOOS
.GOARCH = .GOARCH
.API = nil
for , := range .API {
:= *
.Children = nil
.GOOS = .GOOS
.GOARCH = .GOARCH
.Children = append(.Children, .Children...)
.API = append(.API, &)
}
.docs = append(.docs, &)
continue
}
, , , , , := loadPackageForBuildContext(,
, , , )
for , := range {
.GOOS = .GOOS
.GOARCH = .GOARCH
}
switch {
continue
continue
return nil,
func ( context.Context, map[string][]byte, string, *source.Info, *godoc.ModuleInfo) (
string, []string, string, []byte, []*internal.Symbol, error) {
:= .ModulePath
defer derrors.Wrap(&, "loadPackageWithBuildContext(files, %q, %q, %+v)", , , )
, , , := loadFilesWithBuildContext(, )
if != nil {
return "", nil, "", nil, nil,
}
:= godoc.NewPackage(, .ModulePackages)
for , := range {
if == stdlib.ModulePath && == "builtin" {
= false
}
.AddFile(, )
}
var (
= token.NewFileSet()
= make(map[string]*ast.File)
int
string
string // Name of file where packageName came from.
)
for , := range {
, := parser.ParseFile(, , , parser.ParseComments)
if != nil {
if == nil {
return "", nil, nil, fmt.Errorf("internal error: the source couldn't be read: %v", )
}
return "", nil, nil, &BadPackageError{Err: }
SplitPathList: func(string) []string { panic("internal error: unexpected call to SplitPathList") },
IsAbsPath: func(string) bool { panic("internal error: unexpected call to IsAbsPath") },
IsDir: func(string) bool { panic("internal error: unexpected call to IsDir") },
HasSubdir: func(string, string) (string, bool) { panic("internal error: unexpected call to HasSubdir") },
ReadDir: func(string) ([]os.FileInfo, error) { panic("internal error: unexpected call to ReadDir") },
}
func ( *zip.File, int64) ( []byte, error) {
defer derrors.Add(&, "readZipFile(%q)", .Name)
, := .Open()
if != nil {
return nil, fmt.Errorf("f.Open(): %v", )
}
, := ioutil.ReadAll(io.LimitReader(, ))
if != nil {
.Close()
return nil, fmt.Errorf("ioutil.ReadAll(r): %v", )
}
if := .Close(); != nil {
return nil, fmt.Errorf("closing: %v", )
}
return , nil
}
const mib = 1024 * 1024
var maxModuleZipSize int64 = math.MaxInt64
func () {
:= config.GetEnvInt("GO_DISCOVERY_MAX_MODULE_ZIP_MI", -1)
if > 0 {
maxModuleZipSize = int64() * mib
}
}
var zipLoadShedder *loadShedder
func () {
:= context.Background()
:= config.GetEnvInt("GO_DISCOVERY_MAX_IN_FLIGHT_ZIP_MI", -1)
if > 0 {
log.Infof(, "shedding load over %dMi", )
zipLoadShedder = &loadShedder{maxSizeInFlight: uint64() * mib}
}
}
func () LoadShedStats {
if zipLoadShedder != nil {
return zipLoadShedder.stats()
}
return LoadShedStats{}
![]() |
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. |