安装
- Go 1.21+ - Fox 需要 Go 1.21 或更高版本
- Git - 用于版本控制和依赖管理
安装 Fox
Section titled “安装 Fox”使用 go get
Section titled “使用 go get”安装 Fox 最简单的方法是使用 go get:
go get -u github.com/fox-gonic/fox这将下载 Fox 及其依赖项,包括 Gin。
使用 Go Modules
Section titled “使用 Go Modules”如果您正在开始一个新项目:
# 创建新目录mkdir myprojectcd myproject
# 初始化 Go modulego mod init myproject
# 安装 Foxgo get -u github.com/fox-gonic/fox安装特定版本的 Fox:
go get github.com/fox-gonic/fox@v0.1.0创建一个简单的测试文件 main.go:
package main
import ( "github.com/fox-gonic/fox")
func main() { r := fox.Default() r.GET("/ping", func() string { return "pong" }) r.Run(":8080")}运行它:
go run main.go在浏览器中访问 http://localhost:8080/ping,您应该看到 “pong”。
-
Air - Go 应用的热重载
Terminal window go install github.com/cosmtrek/air@latest -
Delve - Go 调试器
Terminal window go install github.com/go-delve/delve/cmd/dlv@latest
IDE 设置
Section titled “IDE 设置”VS Code
安装 Go 扩展:
- 提供智能感知、调试等功能
- 配置 gopls 以获得最佳体验
GoLand
GoLand 内置了对 Go 的支持。只需打开您的项目即可开始使用。
更新 Fox
Section titled “更新 Fox”更新到最新版本:
go get -u github.com/fox-gonic/foxgo mod tidy导入循环错误
Section titled “导入循环错误”如果遇到导入循环错误,请确保项目结构清晰,并且没有创建循环依赖。
Gin 版本冲突
Section titled “Gin 版本冲突”Fox 依赖于特定版本的 Gin。如果您遇到版本冲突:
go mod tidygo clean -modcachego get -u github.com/fox-gonic/fox如果遇到构建错误:
- 确保使用 Go 1.21+:
go version - 清理模块缓存:
go clean -modcache - 重新下载依赖项:
go mod download