如何设置go服务器使其与AngularJS html5mode兼容?

I am using the julienschmidt/httprouter alongside with http.FileServer.

Something like this:

func main() {
    router := httprouter.New()
    router.NotFound = http.FileServer(http.Dir("/srv/www/public_html"))
    router.GET("/api/user/:id", getUserbyId)
    log.Fatal(http.ListenAndServe(":80", router))
}

So if a route is not found just serve them from root dir "/"

But this does not work as intended. In nginx I do it like this

location / {
        autoindex on;
        try_files $uri $uri/ /index.html =404;
}

Check if there are any files in the given url, if not then give them /index.html

How can I make the server compatible with AngularJS html5mode?

If route is not found, add

router.GET("/", Yourfunction)

and your function as,

func Yourfunction(res http.ResponseWriter, req *http.Request) {
    file, _ := ioutil.ReadFile("/srv/www/public_html")
    t := template.New("")
    t, _ = t.Parse(string(file))

    t.Execute(res, nil)
}