er{&pizzas})
117 mux.Handle("/orders", ordersHandler{&pizzas, &orders})
118
119 log.Fatal(http.ListenAndServe(":8080", mux))
120 }
pizzas 和 orders 数据都保留在内存中,为了尽可能简单,没有任何数据存储持久化,如果需要,我可以开设另一篇来讲 gorm 之类的,也是现学的 :)
也不检查请求的header,客户端发的data body
Source code
运行
本地启动
### https://www.cnblogs.com/wade-xu/p/16705918.html ###
测试
调用 get all pizzas 接口
创建一个 order 订4个 Veggie pizzas
curl -X POST localhost:8080/orders -d '{"pizza_id":1,"quantity":4}' | jq
再创建一个Order 订2个 Cheese pizzas
curl -X POST localhost:8080/orders -d '{"pizza_id":2,"quantity":2}' | jq
{
"pizza_id": 2,
"quantity": 2,
"total": 22
}
最后 Get orders 看下
Simple HTTP server works well.
### https://www.cnblogs.com/wade-xu/p/16705918.html ###
感谢阅读,如果您觉得本文的内容对您的学习有所帮助,您可以打赏和推荐,您的鼓励是我创作的动力。