个人项目小结
分工
本次项目中我主要负责后端api设计和URL的解析
实验内容
API实现目标
页面数与API数限制
- 界面不能少于三个界面
- 用户注册(/register POST)
- 用户登陆(/login POST)
- 获取资源目录(/api/ GET)
- 游客登陆
- 服务API不能少于六个
- films资源
- /api/films/?page={id} GET
- /api/films/pages GET
- /api/films/{id} GET
- planets资源
- /api/planets/?page={id} GET
- /api/planets/pages GET
- /api/planets/{id} GET
- people资源
- /api/people/?page={id} GET
- /api/people/pages GET
- /api/people/{id} GET
- species资源
- /api/species/?page={id} GET
- /api/species/pages GET
- /api/species/{id} GET
- starships资源
- /api/starships/?page={id} GET
- /api/starships/pages GET
- /api/starships/{id} GET
- vehicles资源
- /api/vehicles/?page={id} GET
- /api/vehicles/pages GET
- /api/vehicles/{id} GET
- films资源
具体代码
json序列化和反序列化
服务器端收到请求后使用json解析器反序列化为结构体
comment := &Comment{
Date: time.Now().Format("2006-01-02 15:04:05"),
Content: "",
Author: "",
ArticleId: Id,
}
err = json.NewDecoder(r.Body).Decode(&comment)
服务器端发送响应时将结构体序列化为字符串
json, err := json.Marshal(response)
用户注册登陆
func registerHandler(w http.ResponseWriter, req *http.Request) {
}
func loginHandler(w http.ResponseWriter, req *http.Request) {
}
handle一个GET 请求
func apiHandler(formatter *render.Render) negroni.HandlerFunc {
return func</