Используйте путь, заканчивающийся на "/", чтобы соответствовать целому поддереву с http.ServeMux .
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
// The "/" matches anything not handled elsewhere. If it's not the root
// then report not found.
if r.URL.Path != "/" {
http.NotFound(w, r)
return
}
io.WriteString(w, "Hello World!")
})
http.HandleFunc("/health", func(w http.ResponseWriter, r *http.Request) {
io.WriteString(w, "OK")
})
http.HandleFunc("/es/", func(w http.ResponseWRiter, r *http.Request) {
// The path "/es/" matches the tree with prefix "/es/".
log.Printf("es called with path %s", strings.TrimPrefix(r.URL.Path, "/es/"))
w.Header().Set("Content-Type", "application/json; charset=utf-8")
io.WriteString(w, `{"version":{"number":"6.0.0"}}`)
}
Если шаблон "/ es" не зарегистрирован, то мультиплексированиеперенаправляет "/ es" в "/ es /".