From 8ea9f1433b070f748f23e187a4a688162640c574 Mon Sep 17 00:00:00 2001 From: Feuerfuchs Date: Sun, 17 Nov 2019 10:22:55 +0100 Subject: Allow custom path for startpage file --- cmd/gopherproxy/main.go | 3 ++- gopherproxy.go | 4 ++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/cmd/gopherproxy/main.go b/cmd/gopherproxy/main.go index e84e978..6e6f48c 100644 --- a/cmd/gopherproxy/main.go +++ b/cmd/gopherproxy/main.go @@ -11,6 +11,7 @@ var ( // TODO: Allow config file and environment vars // (opt -> env -> config -> default) bind = flag.String("bind", "0.0.0.0:8000", "[int]:port to bind to") + startpagefile = flag.String("startpage-file", "startpage.txt", "Default page to display if no URL is specified") robotsfile = flag.String("robots-file", "robots.txt", "robots.txt file") robotsdebug = flag.Bool("robots-debug", false, "print output about ignored robots.txt") vipsconcurrency = flag.Int("vips-concurrency", 1, "Concurrency level of libvips") @@ -20,5 +21,5 @@ func main() { flag.Parse() // Use a config struct - log.Fatal(gopherproxy.ListenAndServe(*bind, *robotsfile, *robotsdebug, *vipsconcurrency)) + log.Fatal(gopherproxy.ListenAndServe(*bind, *startpagefile, *robotsfile, *robotsdebug, *vipsconcurrency)) } diff --git a/gopherproxy.go b/gopherproxy.go index 2a6358c..9a081dc 100644 --- a/gopherproxy.go +++ b/gopherproxy.go @@ -539,7 +539,7 @@ func FontHandler(woff2 bool, fontdata []byte) http.HandlerFunc { // specified by the request. The robots argument is a pointer to // a robotstxt.RobotsData struct for testing user agents against // a configurable robots.txt file. -func ListenAndServe(bind, robotsfile string, robotsdebug bool, vipsconcurrency int) error { +func ListenAndServe(bind, startpagefile string, robotsfile string, robotsdebug bool, vipsconcurrency int) error { var ( tpl *template.Template robotsdata *robotstxt.RobotsData @@ -600,7 +600,7 @@ func ListenAndServe(bind, robotsfile string, robotsdebug bool, vipsconcurrency i favicondata = []byte{} } - startpagedata, err := ioutil.ReadFile("startpage.txt") + startpagedata, err := ioutil.ReadFile(startpagefile) if err != nil { startpagedata = []byte{} } -- cgit v1.2.3-54-g00ecf