Go 语言基础语法:Web 版 Hello World 0 个改进

下面是使用标准库 net/http 实现 Web 版本的 Hello World 程序:

package main

import (
    "fmt"
    "net/http"
)

func main() {
    http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
        fmt.Fprint(w, "Hello, World!")
    })
    fmt.Println("Please Visit -  http://localhost:8888/")
    http.ListenAndServe(":8888", nil)
}

保存为 hello.go ,运行代码:

$ go run hello.go
Please Visit -  http://localhost:8888/

打开浏览器访问: localhost:8888/

Web 版本的 Hello World

本文为 Wiki 文章,邀您参与纠错、纰漏和优化
讨论数量: 0
(= ̄ω ̄=)··· 暂无内容!

讨论应以学习和精进为目的。请勿发布不友善或者负能量的内容,与人为善,比聪明更重要!