-
package main
-
import "net/http"
-
import "io"
-
import "os"
-
import "log"
-
type HttpHander struct{}
-
type Mstring string
-
func main() {
-
mux := http.NewServeMux()
-
mux.Handle("/", HttpHander{})
-
//获取当前路径
-
wd, err := os.Getwd()
-
if err != nil {
-
log.Fatalln(err)
-
}
-
//func StripPrefix(prefix string, h Handler) Handler
-
// 给定url 删除前缀
-
mux.Handle("/static/", http.StripPrefix("/static", http.FileServer(http.Dir(wd))))
-
http.HandleFunc("/", sayHello)
-
http.ListenAndServe(":8080", mux)
-
}
-
func (HttpHander) ServeHTTP(response http.ResponseWriter, request *http.Request) {
-
io.WriteString(response, "ServeHTTP")
-
}
-
func sayHello(response http.ResponseWriter, request *http.Request) {
-
io.WriteString(response, "sayHello")
-
}
地址栏输入: http://localhost:8080/static/
**
原文
https://studygolang.com/articles/18114
本站部分文章源于互联网,本着传播知识、有益学习和研究的目的进行的转载,为网友免费提供。如有著作权人或出版方提出异议,本站将立即删除。如果您对文章转载有任何疑问请告之我们,以便我们及时纠正。PS:推荐一个微信公众号: askHarries 或者qq群:474807195,里面会分享一些资深架构师录制的视频录像:有Spring,MyBatis,Netty源码分析,高并发、高性能、分布式、微服务架构的原理,JVM性能优化这些成为架构师必备的知识体系。还能领取免费的学习资源,目前受益良多

转载请注明原文出处:Harries Blog™ » golang 静态文件资源服务器设置2 Main.go代码<embed wmode="transparent" src="https://qq4668620…