分享
GoLang Web项目代码生成器
aside section ._1OhGeD · · 3154 次点击 · · 开始浏览这是一个创建于 的文章,其中的信息可能已经有所发展或是发生改变。
https://github.com/lmfuture-ma/lmaker
lmaker - go项目代码生成
快速生成一个golang项目,扩展性强,加快接口开发。
安装依赖
使用proto协议,定义接口,也是项目生成起点,需要本地安装 [protoc](https://github.com/grpc-ecosystem/grpc-gateway)
Then use go get -u to download the following packages:
go get -u github.com/grpc-ecosystem/grpc-gateway/protoc-gen-grpc-gateway
go get -u github.com/grpc-ecosystem/grpc-gateway/protoc-gen-swagger
go get -u github.com/golang/protobuf/protoc-gen-go
使用
git clone https://github.com/lmfuture-ma/lmaker.git
cd lmaker
go install
// todolist 为项目名,切换到你的gopath下
lmaker create -name=todolist
//测试
cd todolist
go build . ==>生成二进制包 todolist
./todolist ==>运行 端口默认8088
初始化共三个接口
// add
curl -X POST -H "Content-Type: application/json" -d '{"addTodoReq":{"id":2,"author":"lmaker3","description":"first+1 todo","done":true,"createdAt":"2019年10月11日"}}' localhost:8088/addTodo
curl -X POST -H "Content-Type: application/json" -d '{"addTodoReq":{"id":2,"author":"lmaker3","description":"first+1 todo","done":true,"createdAt":"2019年10月11日"}}' localhost:8088/addTodo
// list
curl -X GET -H "Content-Type: application/json" localhost:8088/listTodos
// get
curl -X GET -H "Content-Type: application/json" localhost:8088/getTodo/2
API扩展
cd todolist
//1. 更改 pb/*.proto文件
lmaker gen
// 2. 完成server目录下完成接口实现
后续
- grpc 自动生成
- 配置文件
- 中间件 trace,log等
- gorm框架继承
有疑问加站长微信联系(非本文作者)
入群交流(和以上内容无关):加入Go大咖交流群,或添加微信:liuxiaoyan-s 备注:入群;或加QQ群:692541889
关注微信3154 次点击
添加一条新回复
(您需要 后才能回复 没有账号 ?)
- 请尽量让自己的回复能够对别人有帮助
- 支持 Markdown 格式, **粗体**、~~删除线~~、
`单行代码` - 支持 @ 本站用户;支持表情(输入 : 提示),见 Emoji cheat sheet
- 图片支持拖拽、截图粘贴等方式上传
收入到我管理的专栏 新建专栏
https://github.com/lmfuture-ma/lmaker
lmaker - go项目代码生成
快速生成一个golang项目,扩展性强,加快接口开发。
安装依赖
使用proto协议,定义接口,也是项目生成起点,需要本地安装 [protoc](https://github.com/grpc-ecosystem/grpc-gateway)
Then use go get -u to download the following packages:
go get -u github.com/grpc-ecosystem/grpc-gateway/protoc-gen-grpc-gateway
go get -u github.com/grpc-ecosystem/grpc-gateway/protoc-gen-swagger
go get -u github.com/golang/protobuf/protoc-gen-go
使用
git clone https://github.com/lmfuture-ma/lmaker.git
cd lmaker
go install
// todolist 为项目名,切换到你的gopath下
lmaker create -name=todolist
//测试
cd todolist
go build . ==>生成二进制包 todolist
./todolist ==>运行 端口默认8088
初始化共三个接口
// add
curl -X POST -H "Content-Type: application/json" -d '{"addTodoReq":{"id":2,"author":"lmaker3","description":"first+1 todo","done":true,"createdAt":"2019年10月11日"}}' localhost:8088/addTodo
curl -X POST -H "Content-Type: application/json" -d '{"addTodoReq":{"id":2,"author":"lmaker3","description":"first+1 todo","done":true,"createdAt":"2019年10月11日"}}' localhost:8088/addTodo
// list
curl -X GET -H "Content-Type: application/json" localhost:8088/listTodos
// get
curl -X GET -H "Content-Type: application/json" localhost:8088/getTodo/2
API扩展
cd todolist
//1. 更改 pb/*.proto文件
lmaker gen
// 2. 完成server目录下完成接口实现
后续
- grpc 自动生成
- 配置文件
- 中间件 trace,log等
- gorm框架继承