aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFeuerfuchs <git@feuerfuchs.dev>2019-11-17 10:22:55 +0100
committerFeuerfuchs <git@feuerfuchs.dev>2019-11-17 10:22:55 +0100
commit8ea9f1433b070f748f23e187a4a688162640c574 (patch)
treed6517705321a32dfbf24ea85830ea1b5574cde10
parentReport template errors, add support for start page (diff)
downloadgopherproxy-8ea9f1433b070f748f23e187a4a688162640c574.tar.gz
gopherproxy-8ea9f1433b070f748f23e187a4a688162640c574.tar.bz2
gopherproxy-8ea9f1433b070f748f23e187a4a688162640c574.zip
Allow custom path for startpage file
-rw-r--r--cmd/gopherproxy/main.go3
-rw-r--r--gopherproxy.go4
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 (
11 // TODO: Allow config file and environment vars 11 // TODO: Allow config file and environment vars
12 // (opt -> env -> config -> default) 12 // (opt -> env -> config -> default)
13 bind = flag.String("bind", "0.0.0.0:8000", "[int]:port to bind to") 13 bind = flag.String("bind", "0.0.0.0:8000", "[int]:port to bind to")
14 startpagefile = flag.String("startpage-file", "startpage.txt", "Default page to display if no URL is specified")
14 robotsfile = flag.String("robots-file", "robots.txt", "robots.txt file") 15 robotsfile = flag.String("robots-file", "robots.txt", "robots.txt file")
15 robotsdebug = flag.Bool("robots-debug", false, "print output about ignored robots.txt") 16 robotsdebug = flag.Bool("robots-debug", false, "print output about ignored robots.txt")
16 vipsconcurrency = flag.Int("vips-concurrency", 1, "Concurrency level of libvips") 17 vipsconcurrency = flag.Int("vips-concurrency", 1, "Concurrency level of libvips")
@@ -20,5 +21,5 @@ func main() {
20 flag.Parse() 21 flag.Parse()
21 22
22 // Use a config struct 23 // Use a config struct
23 log.Fatal(gopherproxy.ListenAndServe(*bind, *robotsfile, *robotsdebug, *vipsconcurrency)) 24 log.Fatal(gopherproxy.ListenAndServe(*bind, *startpagefile, *robotsfile, *robotsdebug, *vipsconcurrency))
24} 25}
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 {
539// specified by the request. The robots argument is a pointer to 539// specified by the request. The robots argument is a pointer to
540// a robotstxt.RobotsData struct for testing user agents against 540// a robotstxt.RobotsData struct for testing user agents against
541// a configurable robots.txt file. 541// a configurable robots.txt file.
542func ListenAndServe(bind, robotsfile string, robotsdebug bool, vipsconcurrency int) error { 542func ListenAndServe(bind, startpagefile string, robotsfile string, robotsdebug bool, vipsconcurrency int) error {
543 var ( 543 var (
544 tpl *template.Template 544 tpl *template.Template
545 robotsdata *robotstxt.RobotsData 545 robotsdata *robotstxt.RobotsData
@@ -600,7 +600,7 @@ func ListenAndServe(bind, robotsfile string, robotsdebug bool, vipsconcurrency i
600 favicondata = []byte{} 600 favicondata = []byte{}
601 } 601 }
602 602
603 startpagedata, err := ioutil.ReadFile("startpage.txt") 603 startpagedata, err := ioutil.ReadFile(startpagefile)
604 if err != nil { 604 if err != nil {
605 startpagedata = []byte{} 605 startpagedata = []byte{}
606 } 606 }