Source File
datasource.go
Belonging Package
golang.org/x/pkgsite/internal/proxydatasource
package proxydatasource
import (
)
var _ internal.DataSource = (*DataSource)(nil)
func ( *proxy.Client) *DataSource {
return newDataSource(, source.NewClient(1*time.Minute))
}
func ( *proxy.Client) *DataSource {
return newDataSource(, source.NewClientForTesting())
}
func ( *proxy.Client, *source.Client) *DataSource {
return &DataSource{
proxyClient: ,
sourceClient: ,
versionCache: make(map[versionKey]*versionEntry),
modulePathToVersions: make(map[string][]string),
packagePathToModules: make(map[string][]string),
bypassLicenseCheck: false,
}
}
func ( *proxy.Client) *DataSource {
:= New()
.bypassLicenseCheck = true
return
}
type DataSource struct {
proxyClient *proxy.Client
sourceClient *source.Client
packagePathToModules map[string][]string
bypassLicenseCheck bool
}
type versionKey struct {
modulePath, version string
}
func ( *DataSource) ( context.Context, , string, internal.BuildContext) ( *internal.Module, error) {
defer derrors.Wrap(&, "getModule(%q, %q)", , )
:= versionKey{, }
.mu.Lock()
defer .mu.Unlock()
if , := .versionCache[]; {
return .module, .err
}
:= fetch.FetchModule(, , , .proxyClient, .sourceClient)
defer .Defer()
:= .Module
if != nil {
if .bypassLicenseCheck {
.IsRedistributable = true
for , := range .Packages() {
.IsRedistributable = true
}
} else {
.RemoveNonRedistributableData()
, := fetch.LatestModuleVersions(, , .proxyClient, nil)
if != nil {
.Error =
} else {
.PopulateModuleInfo(&.ModuleInfo)
}
}
if .Error != nil {
if !errors.Is(.Err(), context.Canceled) {
.versionCache[] = &versionEntry{module: , err: .Error}
}
return nil, .Error
}
.versionCache[] = &versionEntry{module: , err: }
:= append(.modulePathToVersions[], )
sort.Slice(, func(, int) bool {
return semver.Compare([], []) < 0
})
.modulePathToVersions[] =
func ( *DataSource) ( context.Context, string, string) ( string, *proxy.VersionInfo, error) {
defer derrors.Wrap(&, "findModule(%q, ...)", )
= strings.TrimLeft(, "/")
for , := range internal.CandidateModulePaths() {
, := .proxyClient.Info(, , )
if errors.Is(, derrors.NotFound) {
continue
}
if != nil {
return "", nil,
}
return , , nil
}
return "", nil, fmt.Errorf("unable to find module: %w", derrors.NotFound)
}
func ( *DataSource) ( context.Context, , , string, internal.BuildContext) ( *internal.Unit, error) {
var *internal.Module
, = .getModule(, , , )
if != nil {
return nil,
}
for , := range .Units {
if .Path == {
return , nil
}
}
return nil, fmt.Errorf("%q missing from module %s: %w", , .ModulePath, derrors.NotFound)
}
func ( *DataSource) ( context.Context, , string, *internal.UnitMeta) ( internal.LatestInfo, error) {
defer derrors.Wrap(&, "GetLatestInfo(ctx, %q, %q)", , )
if == nil {
, = .GetUnitMeta(, , internal.UnknownModulePath, internal.LatestVersion)
if != nil {
return ,
}
}
.MinorVersion = .Version
.MinorModulePath = .ModulePath
.MajorModulePath, .MajorUnitPath, = .getLatestMajorVersion(, , )
if != nil {
return ,
.UnitExistsAtMinor = true
return , nil
}
:= internal.SeriesPathForModule()
, := .proxyClient.Info(, , internal.LatestVersion)
if != nil {
return "", "",
}
![]() |
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. |