创建gomod项目
go mod init web01
新建main.go
package main
import (
"fmt"
"net/http"
)
func handler(writer http.ResponseWriter, request *http.Request) {
fmt.Fprintf(writer, "Hello World,%s!", request.URL.Path[1:])
}
func main() {
fmt.Println("http:127.0.0.1:8080")
http.HandleFunc("/", handler)
http.ListenAndServe(":8080", nil)
}
创建launch.json文章来源:https://www.toymoban.com/news/detail-705338.html
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Launch Package",
"type": "go",
"request": "launch",
"mode": "auto",
"program": "${fileDirname}"
}
]
}
启动项目访问http://127.0.0.1:8080/
文章来源地址https://www.toymoban.com/news/detail-705338.html
到了这里,关于goweb入门的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!