diff options
author | Feuerfuchs <git@feuerfuchs.dev> | 2019-06-30 11:35:20 +0200 |
---|---|---|
committer | Feuerfuchs <git@feuerfuchs.dev> | 2019-06-30 11:35:20 +0200 |
commit | f3849727ca8e83d88bbd6a521601359d41c62357 (patch) | |
tree | e3e0a768d87850e03e7c8afbf31282d179f46149 | |
parent | Upgrade to packr v2 (diff) | |
download | gopherproxy-f3849727ca8e83d88bbd6a521601359d41c62357.tar.gz gopherproxy-f3849727ca8e83d88bbd6a521601359d41c62357.tar.bz2 gopherproxy-f3849727ca8e83d88bbd6a521601359d41c62357.zip |
Add CLI flag for the concurrency level of libvips
-rw-r--r-- | README.md | 1 | ||||
-rw-r--r-- | cmd/gopherproxy/main.go | 11 | ||||
-rw-r--r-- | gopherproxy.go | 4 |
3 files changed, 9 insertions, 7 deletions
@@ -32,6 +32,7 @@ Arguments: | |||
32 | - `-uri=<uri>`: The default address to open in the proxy (default: "floodgap.com") | 32 | - `-uri=<uri>`: The default address to open in the proxy (default: "floodgap.com") |
33 | - `-robots-file=<file>`: robots.txt file to serve to protect Gopher sites from web crawlers (default: "robots.txt") | 33 | - `-robots-file=<file>`: robots.txt file to serve to protect Gopher sites from web crawlers (default: "robots.txt") |
34 | - `-robots-debug=<true|false>`: Print output about clients ignoring robots.txt (this includes regular browsers) (default: false) | 34 | - `-robots-debug=<true|false>`: Print output about clients ignoring robots.txt (this includes regular browsers) (default: false) |
35 | - `-vips-concurrency=<n>: Concurrency level of libvips (i.e. number of worker threads)` | ||
35 | 36 | ||
36 | 37 | ||
37 | ## Development | 38 | ## Development |
diff --git a/cmd/gopherproxy/main.go b/cmd/gopherproxy/main.go index e9dea18..e699d14 100644 --- a/cmd/gopherproxy/main.go +++ b/cmd/gopherproxy/main.go | |||
@@ -10,15 +10,16 @@ import ( | |||
10 | var ( | 10 | 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 | robotsfile = flag.String("robots-file", "robots.txt", "robots.txt file") | 14 | robotsfile = flag.String("robots-file", "robots.txt", "robots.txt file") |
15 | robotsdebug = flag.Bool("robots-debug", false, "print output about ignored robots.txt") | 15 | robotsdebug = flag.Bool("robots-debug", false, "print output about ignored robots.txt") |
16 | uri = flag.String("uri", "floodgap.com", "<host>:[port] to proxy to") | 16 | uri = flag.String("uri", "floodgap.com", "<host>:[port] to proxy to") |
17 | vipsconcurrency = flag.Int("vips-concurrency", 1, "Concurrency level of libvips") | ||
17 | ) | 18 | ) |
18 | 19 | ||
19 | func main() { | 20 | 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, *uri)) | 24 | log.Fatal(gopherproxy.ListenAndServe(*bind, *robotsfile, *robotsdebug, *vipsconcurrency, *uri)) |
24 | } | 25 | } |
diff --git a/gopherproxy.go b/gopherproxy.go index 0ecfa14..0134f88 100644 --- a/gopherproxy.go +++ b/gopherproxy.go | |||
@@ -242,7 +242,7 @@ func FontHandler(woff2 bool, fontdata []byte) http.HandlerFunc { | |||
242 | // specified by the request. The robots argument is a pointer to | 242 | // specified by the request. The robots argument is a pointer to |
243 | // a robotstxt.RobotsData struct for testing user agents against | 243 | // a robotstxt.RobotsData struct for testing user agents against |
244 | // a configurable robots.txt file. | 244 | // a configurable robots.txt file. |
245 | func ListenAndServe(bind, robotsfile string, robotsdebug bool, uri string) error { | 245 | func ListenAndServe(bind, robotsfile string, robotsdebug bool, vipsconcurrency int, uri string) error { |
246 | var ( | 246 | var ( |
247 | tpl *template.Template | 247 | tpl *template.Template |
248 | robotsdata *robotstxt.RobotsData | 248 | robotsdata *robotstxt.RobotsData |
@@ -329,7 +329,7 @@ func ListenAndServe(bind, robotsfile string, robotsdebug bool, uri string) error | |||
329 | } | 329 | } |
330 | 330 | ||
331 | vips.Startup(&vips.Config{ | 331 | vips.Startup(&vips.Config{ |
332 | ConcurrencyLevel: 0, | 332 | ConcurrencyLevel: vipsconcurrency, |
333 | }) | 333 | }) |
334 | 334 | ||
335 | http.HandleFunc("/", GopherHandler(tpl, robotsdata, AssetHashList{stylehash, jshash, fontwhash, fontw2hash}, robotsdebug, uri)) | 335 | http.HandleFunc("/", GopherHandler(tpl, robotsdata, AssetHashList{stylehash, jshash, fontwhash, fontw2hash}, robotsdebug, uri)) |