Source File
datasource.go
Belonging Package
golang.org/x/pkgsite/internal/localdatasource
package localdatasource
import (
)
type DataSource struct {
sourceClient *source.Client
mu sync.Mutex
loadedModules map[string]*internal.Module
}
func () *DataSource {
return &DataSource{
sourceClient: source.NewClient(1 * time.Minute),
loadedModules: make(map[string]*internal.Module),
}
}
func ( *DataSource) ( context.Context, , string) error {
:= fetch.FetchLocalModule(, , , .sourceClient)
if .Error != nil {
return .Error
}
.Module.IsRedistributable = true
for , := range .Module.Units {
.IsRedistributable = true
}
for , := range .Module.Units {
for , := range .Documentation {
.BuildContexts = append(.BuildContexts, internal.BuildContext{
GOOS: .GOOS,
GOARCH: .GOARCH,
})
}
}
.mu.Lock()
defer .mu.Unlock()
.loadedModules[.ModulePath] = .Module
return nil
}
func ( *DataSource) ( context.Context, *internal.UnitMeta, internal.FieldSet, internal.BuildContext) ( *internal.Unit, error) {
defer derrors.Wrap(&, "GetUnit(%q, %q)", .Path, .ModulePath)
:= .ModulePath
:= .Path
.mu.Lock()
defer .mu.Unlock()
if .loadedModules[] == nil {
return nil, fmt.Errorf("%s not loaded: %w", , derrors.NotFound)
}
:= .loadedModules[]
for , := range .Units {
if .Path == {
return , nil
}
}
return nil, fmt.Errorf("%s not found: %w", , derrors.NotFound)
}
func ( *DataSource) ( context.Context, , , string) ( *internal.UnitMeta, error) {
defer derrors.Wrap(&, "GetUnitMeta(%q, %q, %q)", , , )
if == internal.UnknownModulePath {
, = .findModule()
if != nil {
return nil,
}
}
.mu.Lock()
:= .loadedModules[]
.mu.Unlock()
if == nil {
return nil, fmt.Errorf("%s not loaded: %w", , derrors.NotFound)
}
:= &internal.UnitMeta{
Path: ,
ModuleInfo: internal.ModuleInfo{
ModulePath: ,
Version: fetch.LocalVersion,
CommitTime: fetch.LocalCommitTime,
IsRedistributable: .IsRedistributable,
},
}
for , := range .Units {
if .Path == {
.Name = .Name
.IsRedistributable = .IsRedistributable
}
}
return , nil
}
func ( *DataSource) ( context.Context, , string, *internal.UnitMeta) (internal.LatestInfo, error) {
return internal.LatestInfo{}, nil
}
func ( *DataSource) ( context.Context, string) ([]*internal.ModuleInfo, error) {
return nil, nil
}
![]() |
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. |