Skip to content

Commit

Permalink
cmd/pkgsite: add -http flag
Browse files Browse the repository at this point in the history
A -http flag is added which allows the user to specify which HTTP addr
to listen in on.

For golang/go#40371

Change-Id: Ibfe32281e9a821444df5e538fd7057f39318c546
Reviewed-on: https://go-review.googlesource.com/c/pkgsite/+/290135
Reviewed-by: Jonathan Amsterdam <jba@google.com>
Trust: Julie Qiu <julie@golang.org>
  • Loading branch information
julieqiu committed Feb 5, 2021
1 parent 3b8c4db commit 2579a6b
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions cmd/pkgsite/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,12 @@
//
// The flags are:
//
// -local=path1,path2
// Accepts a GOPATH-like collection of local paths for modules to load to memory
// -gopath_mode=false
// Assume that local modules' paths are relative to GOPATH/src
// -http=:8080
// HTTP service address to listen for incoming requests on
// -local=path1,path2
// Accepts a GOPATH-like collection of local paths for modules to load to memory
package main

import (
Expand All @@ -35,10 +37,13 @@ import (
"golang.org/x/pkgsite/internal/middleware"
)

const defaultAddr = "localhost:8080" // default webserver address

var (
_ = flag.String("static", "content/static", "path to folder containing static files served")
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")
httpAddr = flag.String("http", defaultAddr, "HTTP service address to listen for incoming requests on")
localPaths = flag.String("local", "", "run locally, accepts a GOPATH-like collection of local paths for modules to load to memory")
)

func main() {
Expand Down Expand Up @@ -71,9 +76,8 @@ func main() {
middleware.LatestVersions(server.GetLatestInfo), // must come before caching for version badge to work
middleware.Timeout(54*time.Second),
)
addr := "localhost:6060"
log.Infof(ctx, "Listening on addr %s", addr)
log.Fatal(ctx, http.ListenAndServe(addr, mw(router)))
log.Infof(ctx, "Listening on addr %s", *httpAddr)
log.Fatal(ctx, http.ListenAndServe(*httpAddr, mw(router)))
}

// load loads local modules from pathList.
Expand Down

0 comments on commit 2579a6b

Please sign in to comment.