go 语言基础语法:web 版 hello world | go 技术论坛-380玩彩网官网入口

下面是使用标准库 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/

打开浏览器访问:

web 版本的 hello world

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

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