FileServer handler with some other HTTP handlers

后端 未结 1 1355
佛祖请我去吃肉
佛祖请我去吃肉 2021-02-04 04:25

I\'m trying to start a HTTP server in Go that will serve my own data using my own handlers, but at the same time I would like to use the default http FileServer to serve files.<

相关标签:
1条回答
  • 2021-02-04 04:56

    You need to use the http.StripPrefix handler:

    http.Handle("/files/", http.StripPrefix("/files/", http.FileServer(http.Dir("."))))
    

    See here: http://golang.org/pkg/net/http/#example_FileServer_stripPrefix

    0 讨论(0)
提交回复
热议问题