```go
var langs = map[string]bool{
"cn": true,
"en": true,
"jp": true,
"ru": true,
}
func main() {
var global = http.NewServeMux()
var mux = http.NewServeMux()
mux.HandleFunc("/api/asd", func(w http.ResponseWriter, r *http.Request) {
fmt.Println("hello asadsdd")
fmt.Fprintf(w, "hello format")
})
global.Handle("/{locale}/", http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
fmt.Println(r.PathValue("locale"))
if lng := r.PathValue("locale"); langs[lng] {
http.StripPrefix("/"+lng, mux).ServeHTTP(w, r)
} else {
mux.ServeHTTP(w, r)
}
}))
http.ListenAndServe(":12345", global)
}
```
➜ curl http://localhost:12345/en/api/asd
hello format%
➜ curl http://localhost:12345/cn/api/asd
hello format%
➜ curl http://localhost:12345/api/asd
hello format%
➜ curl http://localhost:12345/ad/api/asd
404 page not found
看效果是满足了的
@
dzdh @
dzdh