Skip to content

Commit 2579a6b

Browse files
committed
cmd/pkgsite: add -http flag
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>
1 parent 3b8c4db commit 2579a6b

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

cmd/pkgsite/main.go

+10-6
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,12 @@
1313
//
1414
// The flags are:
1515
//
16-
// -local=path1,path2
17-
// Accepts a GOPATH-like collection of local paths for modules to load to memory
1816
// -gopath_mode=false
1917
// Assume that local modules' paths are relative to GOPATH/src
18+
// -http=:8080
19+
// HTTP service address to listen for incoming requests on
20+
// -local=path1,path2
21+
// Accepts a GOPATH-like collection of local paths for modules to load to memory
2022
package main
2123

2224
import (
@@ -35,10 +37,13 @@ import (
3537
"golang.org/x/pkgsite/internal/middleware"
3638
)
3739

40+
const defaultAddr = "localhost:8080" // default webserver address
41+
3842
var (
3943
_ = flag.String("static", "content/static", "path to folder containing static files served")
40-
localPaths = flag.String("local", "", "run locally, accepts a GOPATH-like collection of local paths for modules to load to memory")
4144
gopathMode = flag.Bool("gopath_mode", false, "assume that local modules' paths are relative to GOPATH/src, used only with -local")
45+
httpAddr = flag.String("http", defaultAddr, "HTTP service address to listen for incoming requests on")
46+
localPaths = flag.String("local", "", "run locally, accepts a GOPATH-like collection of local paths for modules to load to memory")
4247
)
4348

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

7983
// load loads local modules from pathList.

0 commit comments

Comments
 (0)