title: how to create a prefix route in swagger
body: <p>Usually the examples provided by swagger setup simple servers, where all the api calls for json functions are on the document root.
  e.g. the famous "hello world" sits at "/hello"  .</p>
  
  <p>I want to find a way to define a given prefix, so that can put the a specific api under this prefix. if the prefix would be "/api/2.0", the example api would become</p>
  
  <pre><code>/hello   --&gt; /api/2.0/hello   # The prefix would be "/api/2.0"
  /goodbye --&gt; /api/2.0/goodbye # 
  </code></pre>
  
  <p>in the end i want to keep this dynamic and really provide a commandline switch with some</p>
  
  <pre><code>server -prefix '/api/2.0'
  </code></pre>
  
  <p>and the server would use this for the api. Note that i can then also specify no prefix, and the system should fall back to "/hello" and "/goodbye".</p>
  
  <p>Is this possible with the go-lang implementation of swagger (<a href="https://github.com/go-swagger/go-swagger" rel="nofollow noreferrer">https://github.com/go-swagger/go-swagger</a>) </p>
  
  <p>Can somebody point me to an example / or give a short example?</p>
  
  <p><strong>Addendum</strong>:
  I want to do this basically with a swagger 2.0 interface.
  I learned now that it needs something like this:</p>
  
  <pre><code>http.Handle("/", middlewareOne(middlewareTwo(finalHandler)))
  </code></pre>
  
  <p>Basically the task is to leave the swagger generated "finalHandler" untouched (so it thinks still handles "only" /hello, or /goodbye). But the middleware would catch all traffic before the finalHandler. The "/api/2.0"  would be removed/transformed  (this what i am searching, how???) and the middleware would pass this to the finalhandler, which still believes that it serves /hello. I am not sure if the information that it runs "/api/2.0" is ever neeeded, but mabybe it should be added as context.</p>
  
  <p>See
  <a href="https://github.com/go-swagger/go-swagger/blob/master/docs/use/middleware.md" rel="nofollow noreferrer">https://github.com/go-swagger/go-swagger/blob/master/docs/use/middleware.md</a></p>
  
  <p>Quirky solution, which seems to work.</p>
  
  <pre><code>func setupGlobalMiddleware(handler http.Handler) http.Handler {
    prefix:="/api/2.0"
    return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
      if strings.HasPrefix(r.URL.Path, prefix) {
         r.URL.Path = r.URL.Path[len(prefix):]
      }
      handler.ServeHTTP(w, r)
    })
  }
  </code></pre>
  
  <p>I would rather prefer if would have access to the "handlers" map in the generated code, but it is not accessible. This way i could just "re-register" everything with a prefix. Maybe ther is a better solution?</p>