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

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

内容简介:地址栏输入:
  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资讯^_^


查看所有标签

猜你喜欢:

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

码农翻身

码农翻身

刘欣 / 电子工业出版社 / 2018-6-1 / 69.00元

《码农翻身》用故事的方式讲解了软件编程的若干重要领域,侧重于基础性、原理性的知识。 《码农翻身》分为6章。第1章讲述计算机的基础知识;第2章侧重讲解Java的基础知识;第3章偏重Web后端编程;第4章讲解代码管理的本质;第5章讲述了JavaScript的历史、Node.js的原理、程序的链接、命令式和声明式编程的区别,以及作者十多年来使用各种编程语言的感受;第6章是作者的经验总结和心得体会,......一起来看看 《码农翻身》 这本书的介绍吧!

Base64 编码/解码
Base64 编码/解码

Base64 编码/解码

RGB CMYK 转换工具
RGB CMYK 转换工具

RGB CMYK 互转工具