Golang实现静态文件服务器

5年以前  |  阅读数:502 次  |  编程语言:Golang 
package main

import "net/http"

func main() {
    handler := http.FileServer(http.Dir("./"))
    http.ListenAndServe(":5000", handler)
}

执行程序:

$ go run static-content.go

$ curl http://127.0.0.1:5000/
$ curl http://127.0.0.1:5000/http-server-static.go
$ curl http://127.0.0.1:5000/missing

Copyright© 2013-2020

All Rights Reserved 京ICP备2023019179号-8