内容简介:地址栏输入:
-
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/ **
以上所述就是小编给大家介绍的《golang 静态文件资源服务器设置2 Main.go代码
- golang gorilla/mux设置静态目录
- VMware中CentOS7静态ip的设置
- Spring Boot 设置项目名后静态文件相对路径问题
- IIS如何做http跳转https和伪静态的设置
- 静态库遇到静态库
- 全局变量,静态全局变量,局部变量,静态局部变量
本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们。
Practical Django Projects, Second Edition
James Bennett / Apress / 2009 / 44.99
Build a django content management system, blog, and social networking site with James Bennett as he introduces version 1.1 of the popular Django framework. You’ll work through the development of ea......一起来看看 《Practical Django Projects, Second Edition》 这本书的介绍吧!