设为首页 加入收藏

TOP

云原生之旅 - 1)Golang 入门 简单 HTTP Server(二)
2023-07-23 13:28:06 】 浏览:55
Tags:云原生 Golang 入门 简单 HTTP Server
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

 

运行

本地启动 

go run main.go

### 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 ###

 

感谢阅读,如果您觉得本文的内容对您的学习有所帮助,您可以打赏和推荐,您的鼓励是我创作的动力。

 

首页 上一页 1 2 下一页 尾页 2/2/2
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
上一篇我的Go gRPC之旅、01 初识gRPC,.. 下一篇我的Go gRPC之旅、02 四种通信模式

最新文章

热门文章

Hot 文章

Python

C 语言

C++基础

大数据基础

linux编程基础

C/C++面试题目