内容简介:地址栏输入:
-
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和伪静态的设置
- 静态库遇到静态库
- 全局变量,静态全局变量,局部变量,静态局部变量
本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们。
正则表达式必知必会
Ben Forta / 杨涛、王建桥、杨晓云 / 人民邮电出版社 / 2007 / 29.00元
正则表达式是一种威力无比强大的武器,几乎在所有的程序设计语言里和计算机平台上都可以用它来完成各种复杂的文本处理工作。本书从简单的文本匹配开始,循序渐进地介绍了很多复杂内容,其中包括回溯引用、条件性求值和前后查找,等等。每章都为读者准备了许多简明又实用的示例,有助于全面、系统、快速掌握正则表达式,并运用它们去解决实际问题。 本书适合各种语言和平台的开发人员。一起来看看 《正则表达式必知必会》 这本书的介绍吧!
