You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
21 lines
500 B
21 lines
500 B
package main
|
|
|
|
import (
|
|
"fmt"
|
|
"log"
|
|
"net/http"
|
|
)
|
|
|
|
// 主函数
|
|
func main() {
|
|
//创建一个文件服务器,会去www目录下找index.html
|
|
fileServer := http.FileServer(http.Dir("./www"))
|
|
// 将 "/" 路径映射到文件服务器
|
|
http.Handle("/", fileServer)
|
|
|
|
fmt.Printf("Starting server at port 8080\n")
|
|
// 启动HTTP服务器并监听端口 80,如果出现错误,则打印错误信息并退出
|
|
if err := http.ListenAndServe("localhost:8080", nil); err != nil {
|
|
log.Fatal(err)
|
|
}
|
|
}
|
|
|