title: How to add new methods to an existing type in Go?
body: <p>I want to add a convenience util method on to <code>gorilla/mux</code> Route and Router types:</p>
  
  <pre><code>package util
  
  import(
      "net/http"
      "github.com/0xor1/gorillaseed/src/server/lib/mux"
  )
  
  func (r *mux.Route) Subroute(tpl string, h http.Handler) *mux.Route{
      return r.PathPrefix("/" + tpl).Subrouter().PathPrefix("/").Handler(h)
  }
  
  func (r *mux.Router) Subroute(tpl string, h http.Handler) *mux.Route{
      return r.PathPrefix("/" + tpl).Subrouter().PathPrefix("/").Handler(h)
  }
  </code></pre>
  
  <p>but the compiler informs me</p>
  
  <blockquote>
    <p>Cannot define new methods on non-local type mux.Router</p>
  </blockquote>
  
  <p>So how would I achieve this? Do I create a new struct type that has an anonymous mux.Route and mux.Router fields? Or something else?</p>