Golang搭建静态服务器- 两行代码搞定
发布时间:2020-12-16 18:29:32 所属栏目:大数据 来源:网络整理
导读:windows下,新建文件夹D:webservergowwwsite 并放入一个静态网站的所有文件 新建go源文件 staticweb.go // staticwebpackage mainimport ("net/http")func main() {http.Handle("/",http.FileServer(http.Dir("D:/webserver/gowww/site/")))http.ListenAn
windows下,新建文件夹D:webservergowwwsite 并放入一个静态网站的所有文件
新建go源文件 staticweb.go // staticweb package main import ( "net/http" ) func main() { http.Handle("/",http.FileServer(http.Dir("D:/webserver/gowww/site/"))) http.ListenAndServe(":9090",nil) } F5运行后, 浏览器访问http://localhost:9090
只需两行代码 go来搭建静态web服务器,就是这么简单,这么有效。 (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |