M
M
Michail Wowtschuk2017-07-21 11:18:43
Intellectual property
Michail Wowtschuk, 2017-07-21 11:18:43

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

3 answer(s)
N
nvdfxx, 2019-02-06
@nvdfxx

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

K
kegebinem, 2017-07-21
@kegebinem

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.

A
Alexander Trakhimenok, 2017-07-21
@astec

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 question

Ask a Question

731 491 924 answers to any question