Answer the question
In order to leave comments, you need to log in
ServeMux or Switch?
Tell me how to do it right and so that it works quickly.
There is a MAP with 50 languages, their descriptions and data in each language.
Do separate functions for all 50 languages?
mux.HandleFunc("/", indexHandler)
mux.HandleFunc("/ru", ruHandler)
mux.HandleFunc("/de", deHandler)
mux.HandleFunc("/fr", deHandler)
Or only one function in it handle all languages with Switch
mux.HandleFunc("/", indexHandler)
func indexHandler(w http.ResponseWriter, r *http.Request) {
switch r.URL.Path{
//Search for language in map
case locales[r.URL .Path]:
fmt.Fprintf(w, "%s\n", r.URL) //Language found in map
default:
w.WriteHeader(http.StatusNotFound) // 404
fmt.Fprintf(w, "no such page: %s\n", r.URL)
}
}
Answer the question
In order to leave comments, you need to log in
you can use modified characters to the point of confusion, if you can prove in court that they were invented by you and just look like StarCraft ones, use plots / exact setting, etc. it's forbidden, it's like making a movie based on a book without the writer's permission
How convenient.
It is unlikely that you will distinguish those nanoseconds of difference in speed even when thousands of people come to your site at the same time.
If there is only one page, then it doesn't matter. If there are a lot of pages in each language, then it's probably better to use something like Gorilla mux with template/regex support.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question