1.新建项目与项目文件

2.编写代码
package main
import (
"fmt"
"net/http"
)
func sayHello(w http.ResponseWriter, r *http.Request) {
_, _ = fmt.Fprintf(w, "Hello Golang")
}
func main() {
http.HandleFunc("/hello", sayHello)
err := http.ListenAndServe(":9090", nil)
if err != nil {
fmt.Printf("http serve failed,err:%v\n", err)
return
}
}
3.运行文件
4.测试
本文介绍了如何使用Golang构建一个简单的HTTP服务器,通过`sayHello`函数响应GET请求,并演示了从新建项目到运行测试的完整过程。
1114





