|
| 1 | +# Go语言运行体检中心 - 安装指南 |
| 2 | + |
| 3 | +## 系统要求 |
| 4 | + |
| 5 | +- Windows 10/11 (当前系统) |
| 6 | +- 管理员权限(用于安装Go) |
| 7 | + |
| 8 | +## 安装Go语言环境 |
| 9 | + |
| 10 | +### 1. 下载Go安装包 |
| 11 | + |
| 12 | +访问 [Go官网下载页面](https://golang.org/dl/) 或使用以下链接: |
| 13 | + |
| 14 | +- **Windows 64位**: https://golang.org/dl/go1.21.5.windows-amd64.msi |
| 15 | +- **Windows 32位**: https://golang.org/dl/go1.21.5.windows-386.msi |
| 16 | + |
| 17 | +### 2. 安装Go |
| 18 | + |
| 19 | +1. 下载对应版本的MSI安装包 |
| 20 | +2. 双击运行安装程序 |
| 21 | +3. 按照向导完成安装(建议使用默认安装路径:`C:\Program Files\Go`) |
| 22 | +4. 安装完成后,Go会自动添加到系统PATH环境变量中 |
| 23 | + |
| 24 | +### 3. 验证安装 |
| 25 | + |
| 26 | +打开新的PowerShell窗口,运行以下命令验证安装: |
| 27 | + |
| 28 | +```powershell |
| 29 | +go version |
| 30 | +``` |
| 31 | + |
| 32 | +如果显示Go版本信息(如 `go version go1.21.5 windows/amd64`),说明安装成功。 |
| 33 | + |
| 34 | +### 4. 配置Go环境(可选) |
| 35 | + |
| 36 | +如果需要配置Go代理(提高依赖下载速度),运行: |
| 37 | + |
| 38 | +```powershell |
| 39 | +go env -w GOPROXY=https://goproxy.cn,direct |
| 40 | +go env -w GOSUMDB=sum.golang.google.cn |
| 41 | +``` |
| 42 | + |
| 43 | +## 安装项目依赖 |
| 44 | + |
| 45 | +安装Go后,在项目目录下运行: |
| 46 | + |
| 47 | +```powershell |
| 48 | +# 初始化Go模块并下载依赖 |
| 49 | +go mod tidy |
| 50 | +
|
| 51 | +# 验证依赖下载成功 |
| 52 | +go mod download |
| 53 | +``` |
| 54 | + |
| 55 | +## 运行项目 |
| 56 | + |
| 57 | +### 1. 启动Mock服务器 |
| 58 | + |
| 59 | +```powershell |
| 60 | +go run server.go |
| 61 | +``` |
| 62 | + |
| 63 | +服务器将在 `http://localhost:8080` 启动。 |
| 64 | + |
| 65 | +### 2. 运行健康检查(新开一个PowerShell窗口) |
| 66 | + |
| 67 | +```powershell |
| 68 | +go run run_health_center.go health_check_center.go |
| 69 | +``` |
| 70 | + |
| 71 | +### 3. 运行测试 |
| 72 | + |
| 73 | +```powershell |
| 74 | +go run test_health_center.go health_check_center.go |
| 75 | +``` |
| 76 | + |
| 77 | +## 使用Makefile(需要安装make工具) |
| 78 | + |
| 79 | +如果您的系统安装了make工具,可以使用以下命令: |
| 80 | + |
| 81 | +```powershell |
| 82 | +# 下载依赖 |
| 83 | +make deps |
| 84 | +
|
| 85 | +# 启动服务器 |
| 86 | +make server |
| 87 | +
|
| 88 | +# 运行健康检查 |
| 89 | +make run |
| 90 | +
|
| 91 | +# 运行测试 |
| 92 | +make test |
| 93 | +``` |
| 94 | + |
| 95 | +## 故障排除 |
| 96 | + |
| 97 | +### 问题1:`go: 无法将"go"项识别为 cmdlet` |
| 98 | + |
| 99 | +**解决方案**: |
| 100 | +1. 确认Go已正确安装 |
| 101 | +2. 重新打开PowerShell窗口 |
| 102 | +3. 检查PATH环境变量是否包含Go安装目录 |
| 103 | +4. 手动添加到PATH:`$env:PATH += ";C:\Program Files\Go\bin"` |
| 104 | + |
| 105 | +### 问题2:网络连接问题 |
| 106 | + |
| 107 | +**解决方案**: |
| 108 | +```powershell |
| 109 | +# 设置Go代理 |
| 110 | +go env -w GOPROXY=https://goproxy.cn,direct |
| 111 | +go env -w GOSUMDB=sum.golang.google.cn |
| 112 | +``` |
| 113 | + |
| 114 | +### 问题3:端口被占用 |
| 115 | + |
| 116 | +**解决方案**: |
| 117 | +```powershell |
| 118 | +# 查看端口占用 |
| 119 | +netstat -ano | findstr :8080 |
| 120 | +
|
| 121 | +# 终止占用进程(替换PID为实际进程ID) |
| 122 | +taskkill /PID <PID> /F |
| 123 | +``` |
| 124 | + |
| 125 | +## 开发环境推荐 |
| 126 | + |
| 127 | +### 推荐的IDE/编辑器 |
| 128 | + |
| 129 | +1. **Visual Studio Code** + Go扩展 |
| 130 | + - 下载:https://code.visualstudio.com/ |
| 131 | + - Go扩展:在VS Code中搜索并安装"Go" |
| 132 | + |
| 133 | +2. **GoLand**(JetBrains) |
| 134 | + - 下载:https://www.jetbrains.com/go/ |
| 135 | + |
| 136 | +3. **Vim/Neovim** + vim-go插件 |
| 137 | + |
| 138 | +### 有用的Go命令 |
| 139 | + |
| 140 | +```powershell |
| 141 | +# 格式化代码 |
| 142 | +go fmt ./... |
| 143 | +
|
| 144 | +# 代码检查 |
| 145 | +go vet ./... |
| 146 | +
|
| 147 | +# 运行测试 |
| 148 | +go test ./... |
| 149 | +
|
| 150 | +# 构建可执行文件 |
| 151 | +go build -o health-center.exe main.go health_check_center.go |
| 152 | +
|
| 153 | +# 交叉编译(编译为Linux版本) |
| 154 | +set GOOS=linux |
| 155 | +set GOARCH=amd64 |
| 156 | +go build -o health-center-linux main.go health_check_center.go |
| 157 | +``` |
| 158 | + |
| 159 | +## 下一步 |
| 160 | + |
| 161 | +安装完成后,您可以: |
| 162 | + |
| 163 | +1. 阅读 [README.md](README.md) 了解项目功能 |
| 164 | +2. 运行 `go run test_health_center.go health_check_center.go` 测试系统 |
| 165 | +3. 查看源代码了解实现细节 |
| 166 | +4. 根据需求扩展功能 |
| 167 | + |
| 168 | +## 技术支持 |
| 169 | + |
| 170 | +如果遇到问题,请检查: |
| 171 | + |
| 172 | +1. Go版本是否为1.16或更高 |
| 173 | +2. 网络连接是否正常 |
| 174 | +3. 防火墙是否阻止了程序运行 |
| 175 | +4. 端口8080是否被其他程序占用 |
0 commit comments