V
V
Vadim Rublev2020-02-12 23:31:28
go
Vadim Rublev, 2020-02-12 23:31:28

How to edit the URL BEFORE it gets into the http.FileServer() function?

How to edit the URL that opens the static, something like this?:
The Go-server route catches the URL (like - domen.com/blog/L5566 , caught by the handler from the /blog/ fragment); then the end of URL_Path is checked; if it is correct, then we modify the URL to the static_file request format (like domen.com/pages/page10.html), and pass it to the http.FileServer() function.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vladislav, 2020-02-12
@ghostiam

just give the file yourself, why change the url for http.FileServer?
but in general, it's not difficult, replace the URL in r.URL.Path

func handler(w http.ResponseWriter, r *http.Request)  {
  r.URL.Path = "/pages/page10.html"
  http.FileServer(...).ServeHTTP(w,r)
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question