1 回答
TA贡献2051条经验 获得超10个赞
我找到了它,丢失了,下面与我完美配合,并有多个静态文件夹:http.StripPrefix
package main
import (
"embed"
"encoding/json"
"fmt"
"log"
"net/http"
)
//go:embed static
var staticFiles embed.FS
func main() {
go func() {
http.HandleFunc("/favicon.ico", func(rw http.ResponseWriter, r *http.Request) {})
// http.FS can be used to create a http Filesystem
var staticFS = http.FS(staticFiles)
fs := http.FileServer(staticFS) // embeded static files
// Serve static files, to be embedded in the binary
http.Handle("/static/", fs)
// Serve public files, to be beside binary
http.Handle("/public/", http.StripPrefix("/public/", http.FileServer(http.Dir("./files"))))
http.HandleFunc("/getSkills", getSkills)
log.Println("Listening on :3000...")
err := http.ListenAndServe(":3000", nil)
if err != nil {
log.Fatal(err)
}
}
- 1 回答
- 0 关注
- 102 浏览
添加回答
举报