aboutsummaryrefslogtreecommitdiff
path: root/cmd/pkgsite
diff options
context:
space:
mode:
authorJonathan Amsterdam <jba@google.com>2021-08-24 05:44:43 -0400
committerJonathan Amsterdam <jba@google.com>2021-08-24 19:26:05 +0000
commitdaea3ebe1e86d669ba2762a1f83ce4a5d15f8a12 (patch)
tree5b419b9dbdb389499cd26ec3175df2479b66a8ee /cmd/pkgsite
parent9772db757679384861202400baf636292ccd84d4 (diff)
downloadgo-x-pkgsite-daea3ebe1e86d669ba2762a1f83ce4a5d15f8a12.tar.xz
internal/datasource: factor out getters
Move the list of getters into the common dataSource implementation. Also, have the constructor take the list getters initially. It simplifies the state of the dataSource (no chance of someone adding a getter after some modules have been fetched). For golang/go#47780 Change-Id: I08b005da13b7bd1ad784ceaf30d722da634009b2 Reviewed-on: https://go-review.googlesource.com/c/pkgsite/+/344669 Trust: Jonathan Amsterdam <jba@google.com> Run-TryBot: Jonathan Amsterdam <jba@google.com> TryBot-Result: kokoro <noreply+kokoro@google.com> Reviewed-by: Julie Qiu <julie@golang.org>
Diffstat (limited to 'cmd/pkgsite')
-rw-r--r--cmd/pkgsite/main.go11
1 files changed, 6 insertions, 5 deletions
diff --git a/cmd/pkgsite/main.go b/cmd/pkgsite/main.go
index 1d82356f..184523bf 100644
--- a/cmd/pkgsite/main.go
+++ b/cmd/pkgsite/main.go
@@ -67,7 +67,8 @@ func main() {
}
func newServer(ctx context.Context, paths []string, gopathMode bool) (*frontend.Server, error) {
- lds := datasource.NewLocal(source.NewClient(time.Second))
+ getters := buildGetters(ctx, paths, gopathMode)
+ lds := datasource.NewLocal(getters, source.NewClient(time.Second))
server, err := frontend.NewServer(frontend.ServerConfig{
DataSourceGetter: func(context.Context) internal.DataSource { return lds },
StaticPath: template.TrustedSourceFromFlag(flag.Lookup("static").Value),
@@ -75,12 +76,11 @@ func newServer(ctx context.Context, paths []string, gopathMode bool) (*frontend.
if err != nil {
return nil, err
}
- addGetters(ctx, lds, paths, gopathMode)
return server, nil
}
-// load loads local modules from pathList.
-func addGetters(ctx context.Context, ds *datasource.LocalDataSource, paths []string, gopathMode bool) {
+func buildGetters(ctx context.Context, paths []string, gopathMode bool) []fetch.ModuleGetter {
+ var getters []fetch.ModuleGetter
loaded := len(paths)
for _, path := range paths {
var (
@@ -96,11 +96,12 @@ func addGetters(ctx context.Context, ds *datasource.LocalDataSource, paths []str
log.Error(ctx, err)
loaded--
} else {
- ds.AddModuleGetter(mg)
+ getters = append(getters, mg)
}
}
if loaded == 0 {
log.Fatalf(ctx, "failed to load module(s) at %v", paths)
}
+ return getters
}