小编Hig*_*ath的帖子

使用go通过http服务静态文件

在我的html中,我尝试使用

<script src="/js/app.js"></script>
Run Code Online (Sandbox Code Playgroud)

我也尝试过相对路径(来自服务器位置)

<script src="js/app.js"></script>
Run Code Online (Sandbox Code Playgroud)

和相对的HTML文件

我的档案结构

-js
    app.js
-templates
    index.html
hub.go
main.go
Run Code Online (Sandbox Code Playgroud)

main.go是服务器

func main() {
    http.HandleFunc("/", rootHandler)
    http.ListenAndServe(":8080", nil)
}

func rootHandler(w http.ResponseWriter, r *http.Request) {
    http.ServeFile(w, r, "Templates/index.html")
}
Run Code Online (Sandbox Code Playgroud)

我是否丢失了必须通过服务器将CSS / JS服务器化的东西?还是应该简单的HTML工作

go

1
推荐指数
1
解决办法
1442
查看次数

标签 统计

go ×1