Files
golang/golang-learning/10-projects/03-web-server/README.md
2025-08-24 01:01:26 +08:00

804 B

Web 服务器项目

一个简单的 HTTP Web 服务器,提供 RESTful API。

功能特性

  • HTTP 服务器
  • RESTful API 端点
  • JSON 数据处理
  • 路由处理
  • 中间件支持
  • 静态文件服务

API 端点

  • GET / - 首页
  • GET /api/users - 获取用户列表
  • POST /api/users - 创建新用户
  • GET /api/users/{id} - 获取特定用户
  • PUT /api/users/{id} - 更新用户
  • DELETE /api/users/{id} - 删除用户

运行方法

cd 03-web-server
go run main.go

服务器将在 http://localhost:8080 启动

使用示例

# 获取用户列表
curl http://localhost:8080/api/users

# 创建新用户
curl -X POST http://localhost:8080/api/users \
  -H "Content-Type: application/json" \
  -d '{"name":"张三","email":"zhangsan@example.com"}'