cmd/frontend: add -local flag
Create -local and -gopath_mode flags to enable using a local datasource
and loading local modules to memory.
Updates golang/go#40371
Fixes golang/go#40159
Run-TryBot: Jonathan Amsterdam
Trust: Jonathan Amsterdam
TryBot-Result: kokoro
@@ -10,6 +10,7 @@ import (
"flag"
"net/http"
"os"
+ "path/filepath"
"time"
"cloud.google.com/go/profiler"
@@ -23,6 +24,7 @@ import (
"golang.org/x/pkgsite/internal/dcensus"
"golang.org/x/pkgsite/internal/derrors"
"golang.org/x/pkgsite/internal/frontend"
+ "golang.org/x/pkgsite/internal/localdatasource"
"golang.org/x/pkgsite/internal/log"
"golang.org/x/pkgsite/internal/middleware"
"golang.org/x/pkgsite/internal/postgres"
@@ -43,6 +45,8 @@ var (
"for direct proxy mode and frontend fetches")
directProxy = flag.Bool("direct_proxy", false, "if set to true, uses the module proxy referred to by this URL "+
"as a direct backend, bypassing the database")
+ localPaths = flag.String("local", "", "run locally, accepts a GOPATH-like collection of local paths for modules to load to memory")
+ gopathMode = flag.Bool("gopath_mode", false, "assume that local modules' paths are relative to GOPATH/src, used only with -local")
bypassLicenseCheck = flag.Bool("bypass_license_check", false, "display all information, even for non-redistributable paths")
)
@@ -66,14 +70,36 @@ func main() {
dsg func(context.Context) internal.DataSource
fetchQueue queue.Queue
)
- proxyClient, err := proxy.New(*proxyURL)
- if err != nil {
- log.Fatal(ctx, err)
- }
if *bypassLicenseCheck {
log.Info(ctx, "BYPASSING LICENSE CHECKING: DISPLAYING NON-REDISTRIBUTABLE INFORMATION")
}
+
expg := cmdconfig.ExperimentGetter(ctx, cfg)
+ if *localPaths != "" {
+ lds := localdatasource.New()
+ paths := filepath.SplitList(*localPaths)
+ if *gopathMode {
+ for _, path := range paths {
+ err := lds.LoadFromGOPATH(ctx, path)
+ if err != nil {
+ log.Error(ctx, err)
+ }
+ }
+ } else {
+ for _, path := range paths {
+ err := lds.Load(ctx, path)
+ if err != nil {
+ log.Error(ctx, err)
+ }
+ }
+ }
+ dsg = func(context.Context) internal.DataSource { return lds }
+ } else {
+ proxyClient, err := proxy.New(*proxyURL)
+ if err != nil {
+ log.Fatal(ctx, err)
+ }
+
if *directProxy {
var pds *proxydatasource.DataSource
if *bypassLicenseCheck {
@@ -112,6 +138,8 @@ func main() {
log.Fatalf(ctx, "queue.New: %v", err)
}
}
+ }
+
var haClient *redis.Client
if cfg.RedisHAHost != "" {
haClient = redis.NewClient(&redis.Options{
