go-zero docker-compose 搭建课件服务(一):编写服务api和proto
0、转载
go-zero docker-compose 搭建课件服务(一):编写服务api和proto
0.1源码地址
https://github.com/liuyuede123/go-zero-courseware
1、创建项目目录
mkdir go-zero-courseware
cd go-zero-courseware
2、安装goctl
# 安装
GOPROXY=https://goproxy.cn/,direct go install github.com/zeromicro/go-zero/tools/goctl@latest
# mac放到/usr/local/bin/下面
ln -s ~/go/bin/goctl /usr/local/bin/goctl
# 校验
goctl -v
goctl version 1.4.0 darwin/amd64 # 看到版本说明安装成功
3、创建服务
创建服务目录
mkdir -p user/api
mkdir -p user/rpc
mkdir -p courseware/api
mkdir -p courseware/rpc
创建user.api、courseware.api、user.proto、courseware.proto
touch user/api/user.api
touch user/rpc/user.proto
touch courseware/api/courseware.api
touch courseware/rpc/courseware.proto
4、编写user.api、user.proto
type (
// 登录
LoginRequest {
LoginName string `json:"loginName"`
Password string `json:"password"`
}
LoginResponse {
Id uint64 `json:"id"`
Token string `json:"token"`
}
// 注册
RegisterRequest {
LoginName string `json:"loginName"`
Username string `json:"username"`
Password string `json:"password"`
Sex uint64 `json:"sex"`
}
RegisterResponse {
}
// 用户信息
UserInfoRequest {
Id uint64 `json:"id"`
}
UserInfoResponse {
Id uint64 `json:"id"`
Username string `json:"username"`
LoginName string `json:"loginName"`
Sex uint64 `json:"sex"`
}
)
service user {
@handler userLogin
post /api/user/login (LoginRequest) returns (LoginResponse)
@handler userRegister
post /api/user/register (RegisterRequest) returns (RegisterResponse)
@handler userInfo
post /api/user/userInfo (UserInfoRequest) returns (UserInfoResponse)
}
syntax = "proto3";
package user;
option go_package = "./user";
// 登录
message LoginRequest {
string LoginName = 1;
string Password = 2;
}
message LoginResponse {
uint64 Id = 1;
string Token = 2;
}
// 注册
message RegisterRequest {
string LoginName = 1;
string Username = 2;
string Password = 3;
uint64 Sex = 4;
}
message RegisterResponse {
}
// 用户信息
message UserInfoRequest {
uint64 Id = 1;
}
message UserInfoResponse {
uint64 Id = 1;
string Username = 2;
string LoginName = 3;
uint64 Sex = 4;
}
service User {
rpc Login(LoginRequest) returns(LoginResponse);
rpc Register(RegisterRequest) returns(RegisterResponse);
rpc UserInfo(UserInfoRequest) returns(UserInfoResponse);
}
5、编写courseware.api、courseware.proto
type (
// 新增
AddRequest {
Code string `json:"code"`
Name string `json:"name"`
Type uint64 `json:"type"`
}
AddResponse {
}
// 更新
UpdateRequest {
Id uint64 `json:"id"`
Code string `json:"code"`
Name string `json:"name"`
Type uint64 `json:"type"`
}
UpdateResponse {
}
// 查看
GetRequest {
Id uint64 `json:"id"`
}
GetResponse {
Id uint64 `json:"id"`
Code string `json:"code"`
Name string `json:"name"`
Type uint64 `json:"type"`
}
// 删除
DeleteRequest {
Id uint64 `json:"id"`
}
DeleteResponse {
}
)
service courseware {
@handler coursewareAdd
post /api/courseware/add (AddRequest) returns (AddResponse)
@handler coursewareUpdate
post /api/courseware/update (UpdateRequest) returns (UpdateResponse)
@handler coursewareGet
post /api/courseware/get (GetRequest) returns (GetResponse)
@handler coursewareDelete
post /api/courseware/delete (DeleteRequest) returns (DeleteResponse)
}
syntax = "proto3";
package user;
option go_package = "./courseware";
// 新增
message AddRequest {
string Code = 1;
string Name = 2;
uint64 Type = 3;
}
message AddResponse {
}
// 更新
message UpdateRequest {
uint64 Id = 1;
string Code = 2;
string Name = 3;
uint64 Type = 4;
}
message UpdateResponse {
}
// 查看
message GetRequest {
uint64 Id = 1;
}
message GetResponse {
uint64 Id = 1;
string Code = 2;
string Name = 3;
uint64 Type = 4;
}
// 删除
message DeleteRequest {
uint64 Id = 1;
}
message DeleteResponse {
}
service Courseware {
rpc Add(AddRequest) returns(AddResponse);
rpc Update(UpdateRequest) returns(UpdateResponse);
rpc Get(GetRequest) returns(GetResponse);
rpc Delete(DeleteRequest) returns(DeleteResponse);
}
go-zero docker-compose 搭建课件服务(一):编写服务api和proto的更多相关文章
- Istio入门实战与架构原理——使用Docker Compose搭建Service Mesh
本文将介绍如何使用Docker Compose搭建Istio.Istio号称支持多种平台(不仅仅Kubernetes).然而,官网上非基于Kubernetes的教程仿佛不是亲儿子,写得非常随便,不仅缺 ...
- 利用 Docker Compose 搭建 SpringBoot 运行环境(超详细步骤和分析)
0.前言 相信点进来看这篇文章的同学们已经对 Docker Dompose 有一定的了解了,下面,我们拿最简单的例子来介绍如何使用 Docker Compose 来管理项目. 本文例子: 一个应用服务 ...
- 使用Docker Compose搭建Service Mesh
使用Docker Compose搭建Service Mesh 本文将介绍如何使用Docker Compose搭建Istio.Istio号称支持多种平台(不仅仅Kubernetes).然而,官网上非基于 ...
- Docker Compose 搭建 Redis Cluster 集群环境
在前文<Docker 搭建 Redis Cluster 集群环境>中我已经教过大家如何搭建了,本文使用 Docker Compose 再带大家搭建一遍,其目的主要是为了让大家感受 Dock ...
- Docker Compose搭建Redis一主二从三哨兵高可用集群
一.Docker Compose介绍 https://docs.docker.com/compose/ Docker官方的网站是这样介绍Docker Compose的: Compose是用于定义和运行 ...
- docker compose搭建redis7.0.4高可用一主二从三哨兵集群并整合SpringBoot【图文完整版】
一.前言 redis在我们企业级开发中是很常见的,但是单个redis不能保证我们的稳定使用,所以我们要建立一个集群. redis有两种高可用的方案: High availability with Re ...
- windows Docker Desktop 搭建mysql,mssql和redis服务
其实网上关于docker上搭建mysql的文章已经很多了,只是今晚自己搭建的时候遇到一些问题,记录一下 1.首先是pull image , docker pull mysql 2.启动服务 docke ...
- Docker Compose搭建ELK
Elasticsearch默认使用mmapfs目录来存储索引.操作系统默认的mmap计数太低可能导致内存不足,我们可以使用下面这条命令来增加内存: sysctl -w vm.max_map_count ...
- 基于Docker Compose搭建mysql主从复制(1主2从)
系统环境 * 3 Ubuntu 16.04 mysql 8.0.12 docker 18.06.1-ce docker-compose 1.23.0-rc3 *3 ==> PS ###我用的是 ...
- Docker Compose部署GitLab服务,搭建自己的代码托管平台(图文教程)
场景 Docker-Compose简介与Ubuntu Server 上安装Compose: https://blog.csdn.net/BADAO_LIUMANG_QIZHI/article/deta ...
随机推荐
- luoguP4556 [Vani有约会]雨天的尾巴 /【模板】线段树合并 (线段树-权值-动态开点,树链剖分)
中学毕业了,十七号就要前往武汉报道.中学的终点是武汉大学,人生的终点却不是,最初的热情依然失却,我还是回来看看这分类排版皆惨淡的博客吧,只是是用来保存代码也好.想要换一个新博客,带着之前的经验能把它整 ...
- LuoguP2575 高手过招(博弈论)
空格数变吗?不变呀 阶梯博弈阶梯数变吗?不变呀 那这不就阶梯博弈,每行一栋楼,爬完\(mex\)就可以了吗? #include <iostream> #include <cstdio ...
- Luogu1769 淘汰赛制_NOI导刊2010提高(01)(概率DP)
第\(i\)次位置在\(pos_0 / 2^{i - 1}\) #include <iostream> #include <cstdio> #include <cstri ...
- React报错之Expected `onClick` listener to be a function
正文从这开始~ 总览 当我们为元素的onClick属性传递一个值,但是该值却不是函数时,会产生"Expected onClick listener to be a function" ...
- axios请求响应拦截器的应用
什么是axios拦截器? 一般在使用axios时,会用到拦截器的功能,一般分为两种:请求拦截器.响应拦截器. 请求拦截器在请求发送前进行必要操作处理 例如添加统一cookie.请求体加验证.设置请求头 ...
- Spring5中JdbcTemplate
JdbcTemplate是什么 JdbcTemplate 类提供了很多便利的方法解决诸如把数据库数据转变成基本数据类型或对象,执行写好的或可调用的数据库操作语句,提供自定义的数据错误处理. 在spri ...
- 深入分析JVM执行引擎
程序和机器沟通的桥梁 一.闲聊 相信很多朋友在出国旅游,或者与外国友人沟通的过程中,都会遇到语言不通的烦恼.这时候我们就需要掌握对应的外语或者拥有一部翻译机.而笔者只会中文,所以需要借助一部翻译器才能 ...
- session 总结
session 总结(单节点场景) session 称作域对象,一般保存在当前服务器的内存中,如果有很多session也会部分不常用的session"钝化"到磁盘中,若磁盘中的se ...
- [Python]-字典-实践经验总结
字典是Python中常用的一个数据类型. 与列表有相似的用法,表现在列表的下标和字典的键值可以通过相似的方式读取数据: list_name[0] = value dict_name['key'] = ...
- Linux yum安装PostgreSQL9.6
PostgreSQL10版本的主从安装配置在 https://www.cnblogs.com/virtulreal/p/11675841.html 一.下载安装 1.创建PostgreSQL9.6的y ...