GO怎么样搭建网站

43次阅读
没有评论

共计 434 个字符,预计需要花费 2 分钟才能阅读完成。

GO 怎么样搭建网站

GO 使用 http.HandleFunc() 方法搭建一个网站程序,具体方法如下:

1. 使用 http.HandleFunc() 方法获取参数,并保存为 hello.go 文件;

package main

import (

"io"

"log"

"net/http"

)

func helloHandler(w http.ResponseWriter, r *http.Request) {

io.WriteString(w, "Hello, world!")

}

func main() {

http.HandleFunc("/hello", helloHandler)

err := http.ListenAndServe(":8080", nil)

if err != nil {

log.Fatal("ListenAndServe:", err.Error())

}

}

2. 编译 hello.go 文件;

$ go run hello.go

3. 最后,在浏览器中访问 http://localhost:8080/hello 即可;

丸趣 TV 网 – 提供最优质的资源集合!

正文完
 
丸趣
版权声明:本站原创文章,由 丸趣 2023-12-09发表,共计434字。
转载说明:除特殊说明外本站除技术相关以外文章皆由网络搜集发布,转载请注明出处。
评论(没有评论)