I have a static directory, containing a sign.html file :
//go:embed static
var static embed.FS
It is served that way and works fine :
fSys, err := fs.Sub(static, "static")
if err != nil {
return err
}
mux.Handle("/", http.FileServer(http.FS(fSys)))
On some routes though (for instance: /sign), I want to do some checks before serving the page. This is my handler :
func (h Handler) ServeSignPage(w http.ResponseWriter, r *http.Request) error {
publicKey := r.URL.Query().Get("publicKey")
err := h.Service.AuthorizeClientSigning(r.Context(), publicKey)
if err != nil {
return err
}
// this is where I'd like to serve the embed file
// sign.html from the static directory
http.ServeFile(w, r, "sign.html")
return nil
}
Unfortunately, the ServeFile displays not found. How can I serve the file from the file server within that ServeSignPage ?