title: go 1.16: how to use strip prefix in go:embed
body: <p>I have a go project which uses <code>VueJS</code> to provide web interface.  While build the project, I first use <code>npm run build</code> to compile the frontend code, which is generated under <code>gui/dist</code> of my project dir.  Then I use this code to serve the static contents:</p>
  <pre><code>//go:embed gui/dist/*
  var dist embed.FS
  
  gui := http.FileServer(http.FS(dist))
  http.Handle(&quot;/&quot;, gui)
  http.HandleFunc(&quot;/api/&quot;, func(w http.ResponseWriter, r *http.Request) {
      msg := fmt.Sprintf(&quot;TODO: %s&quot;, r.URL)
      http.Error(w, msg, http.StatusNotImplemented)
  })
  
  svr := http.Server{
      Addr:         fmt.Sprintf(&quot;:%v&quot;, cf.HTTPPort),
      ReadTimeout:  time.Minute,
      WriteTimeout: time.Minute,
  }
  assert(svr.ListenAndServe())
  </code></pre>
  <p>The problem is, when open the site in browser, it shows me a browse file interface, i.e. starting with gui, and then into dist, then shows the <code>index.html</code> file, which is a blank page, because it requires files such as <code>/css/...</code>, while the go web server serves it at <code>/gui/dist/css/...</code>.</p>
  <p>I tried to use <code>http.StripPrefix()</code> but apparently it is not intended to handle this situation, or I didn't use it correctly:</p>
  <pre><code>http.Handle(&quot;/&quot;, http.StripPrefix(&quot;/gui/dist&quot;, gui))
  </code></pre>
  <p>which generated a <code>404 page not found</code>.</p>