golang 静态文件资源服务器设置2 Main.go代码<embed wmode="transparent" src="https://qq4668620...

栏目: Java · 发布时间: 7年前

内容简介:地址栏输入:
  1. package main

  2. import "net/http"

  3. import "io"

  4. import "os"

  5. import "log"

  6. type HttpHander struct{}

  7. type Mstring string

  8. func main() {

  9. mux := http.NewServeMux()

  10. mux.Handle("/", HttpHander{})

  11. //获取当前路径

  12. wd, err := os.Getwd()

  13. if err != nil {

  14. log.Fatalln(err)

  15. }

  16. //func StripPrefix(prefix string, h Handler) Handler

  17. // 给定url 删除前缀

  18. mux.Handle("/static/", http.StripPrefix("/static", http.FileServer(http.Dir(wd))))

  19. http.HandleFunc("/", sayHello)

  20. http.ListenAndServe(":8080", mux)

  21. }

  22. func (HttpHander) ServeHTTP(response http.ResponseWriter, request *http.Request) {

  23. io.WriteString(response, "ServeHTTP")

  24. }

  25. func sayHello(response http.ResponseWriter, request *http.Request) {

  26. io.WriteString(response, "sayHello")

  27. }

地址栏输入: http://localhost:8080/static/ **


以上所述就是小编给大家介绍的《golang 静态文件资源服务器设置2 Main.go代码 关注码农网公众号

关注我们,获取更多IT资讯^_^


查看所有标签

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

Agile Web Development with Rails, Third Edition

Agile Web Development with Rails, Third Edition

Sam Ruby、Dave Thomas、David Heinemeier Hansson / Pragmatic Bookshelf / 2009-03-17 / USD 43.95

Rails just keeps on changing. Rails 2, released in 2008, brings hundreds of improvements, including new support for RESTful applications, new generator options, and so on. And, as importantly, we’ve a......一起来看看 《Agile Web Development with Rails, Third Edition》 这本书的介绍吧!

HTML 编码/解码
HTML 编码/解码

HTML 编码/解码

html转js在线工具
html转js在线工具

html转js在线工具

UNIX 时间戳转换
UNIX 时间戳转换

UNIX 时间戳转换