1、找个目录,用命令行进入,执行命令go mod init app (注意:app为任意字符)
2、这时候目录下会生成文件 go.mod
3、在 go.mod 里,写入goframe的引入,如:
module app
require github.com/gogf/gf latest
go 1.17
4、执行代码:go mod tidy (加载依赖)
5、创建main.go,代码如下:
package main
import (
"fmt"
"github.com/gogf/gf/frame/g"
"github.com/gogf/gf/net/ghttp"
)
func main() {
s := g.Server()
s.BindHandler("/", func(r *ghttp.Request) {
r.Response.Write("Hello World!")
})
s.Run() // 默认 80 端口
fmt.Println("server start success")
}
6、执行:go run main.go
7、在浏览器访问:localhost,就能看到输出的 Hello World! 了
至此,goframe就体验成功了