diff options
author | Austin Adams <git@austinjadams.com> | 2016-03-26 00:06:55 -0400 |
---|---|---|
committer | Austin Adams <git@austinjadams.com> | 2016-03-26 00:06:55 -0400 |
commit | 011ba174e60e7003c8f20cbe8f5221f33fcf2e50 (patch) | |
tree | 8db208ef2b5efac51f6bf1b5c0682e71d024c09a | |
parent | f8ccf18b95d02ad71304c00da75858250d013517 (diff) | |
download | toolbag-011ba174e60e7003c8f20cbe8f5221f33fcf2e50.tar.gz toolbag-011ba174e60e7003c8f20cbe8f5221f33fcf2e50.tar.xz |
add prefix-stripping (like -prefix /XYZ)
Now you can run `toolbag -prefix /XYZ' to remove `/XYZ' from paths
before ToolBag's ServeMux processes them. Because I've only wrapped the
ToolBag in a StripPrefix, this still leaves plenty of links horribly
broken, namely the ones generated by the Tools tool. At the moment, it
prints aTool.Path(), an absolute path, without any knowledge of the
stripped prefix.
Still, this change makes testing easier.
-rw-r--r-- | toolbag/main.go | 17 |
1 files changed, 13 insertions, 4 deletions
diff --git a/toolbag/main.go b/toolbag/main.go index 8a1f248..4737515 100644 --- a/toolbag/main.go +++ b/toolbag/main.go @@ -33,11 +33,12 @@ func usage(msg string) { os.Exit(1) } -func args(usefcgi, usehttp *bool, unix, tcp *string) { +func args(usefcgi, usehttp *bool, unix, tcp, prefix *string) { flag.BoolVar(usefcgi, "fcgi", false, "use fastcgi") flag.BoolVar(usehttp, "http", false, "use http") flag.StringVar(unix, "unix", "", "path to a unix socket") flag.StringVar(tcp, "tcp", "", "path to a unix socket") + flag.StringVar(prefix, "prefix", "", "prefix to strip from paths") flag.Parse() // xnor @@ -69,8 +70,8 @@ func main() { // args var usefcgi, usehttp bool - var unix, tcp string - args(&usefcgi, &usehttp, &unix, &tcp) + var unix, tcp, prefix string + args(&usefcgi, &usehttp, &unix, &tcp, &prefix) if err := tb.Init(); err != nil { usage(err.Error()) @@ -91,7 +92,15 @@ func main() { serve = fcgi.Serve } - if err := serve(sock, tb); err != nil { + var handler http.Handler + if prefix == "" { + handler = tb + } else { + handler = http.StripPrefix(prefix, tb) + } + + + if err := serve(sock, handler); err != nil { log.Fatalln("can't serve", err) } } |