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的更多相关文章

  1. Istio入门实战与架构原理——使用Docker Compose搭建Service Mesh

    本文将介绍如何使用Docker Compose搭建Istio.Istio号称支持多种平台(不仅仅Kubernetes).然而,官网上非基于Kubernetes的教程仿佛不是亲儿子,写得非常随便,不仅缺 ...

  2. 利用 Docker Compose 搭建 SpringBoot 运行环境(超详细步骤和分析)

    0.前言 相信点进来看这篇文章的同学们已经对 Docker Dompose 有一定的了解了,下面,我们拿最简单的例子来介绍如何使用 Docker Compose 来管理项目. 本文例子: 一个应用服务 ...

  3. 使用Docker Compose搭建Service Mesh

    使用Docker Compose搭建Service Mesh 本文将介绍如何使用Docker Compose搭建Istio.Istio号称支持多种平台(不仅仅Kubernetes).然而,官网上非基于 ...

  4. Docker Compose 搭建 Redis Cluster 集群环境

    在前文<Docker 搭建 Redis Cluster 集群环境>中我已经教过大家如何搭建了,本文使用 Docker Compose 再带大家搭建一遍,其目的主要是为了让大家感受 Dock ...

  5. Docker Compose搭建Redis一主二从三哨兵高可用集群

    一.Docker Compose介绍 https://docs.docker.com/compose/ Docker官方的网站是这样介绍Docker Compose的: Compose是用于定义和运行 ...

  6. docker compose搭建redis7.0.4高可用一主二从三哨兵集群并整合SpringBoot【图文完整版】

    一.前言 redis在我们企业级开发中是很常见的,但是单个redis不能保证我们的稳定使用,所以我们要建立一个集群. redis有两种高可用的方案: High availability with Re ...

  7. windows Docker Desktop 搭建mysql,mssql和redis服务

    其实网上关于docker上搭建mysql的文章已经很多了,只是今晚自己搭建的时候遇到一些问题,记录一下 1.首先是pull image , docker pull mysql 2.启动服务 docke ...

  8. Docker Compose搭建ELK

    Elasticsearch默认使用mmapfs目录来存储索引.操作系统默认的mmap计数太低可能导致内存不足,我们可以使用下面这条命令来增加内存: sysctl -w vm.max_map_count ...

  9. 基于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  ###我用的是 ...

  10. Docker Compose部署GitLab服务,搭建自己的代码托管平台(图文教程)

    场景 Docker-Compose简介与Ubuntu Server 上安装Compose: https://blog.csdn.net/BADAO_LIUMANG_QIZHI/article/deta ...

随机推荐

  1. Luogu2986 [USACO10MAR]伟大的奶牛聚集 (树形DP)

    有点权的重心,拆掉点dfs不就是了吗 //#include <iostream> #include <cstdio> #include <cstring> //#i ...

  2. java中为什么只存在值传递(以传入自定义引用类型为例)

    java中只有值传递 为什么这么说?两个例子: public class Student { int sage = 20; String sname = "云胡不归"; publi ...

  3. Docker 01 概述

    参考源 https://www.bilibili.com/video/BV1og4y1q7M4?spm_id_from=333.999.0.0 https://www.bilibili.com/vid ...

  4. 自定义spring boot starter 初尝试

    自定义简单spring boot starter 步骤 从几篇博客中了解了如何自定义starter,大概分为以下几个步骤: 1 引入相关依赖: 2 生成属性配置类: 3 生成核心服务类: 4 生成自动 ...

  5. 未来的可再生能源电网!FREEDM 论文阅读

    全文主旨[省时间快读] 背景: 论文标题:The Future Renewable Electric Energy Delivery and Management (FREEDM) System: T ...

  6. 最大连续子序列(简单DP实现)

    最大连续子序列 最大连续子数列和一道很经典的算法问题,给定一个数列,其中可能有正数也可能有负数,我们的任务是找出其中连续的一个子数列(不允许空序列),使它们的和尽可能大.我们一起用多种方式,逐步优化解 ...

  7. CF1528C Trees of Tranquillity(图论,数据结构)

    题面 有两棵 n n n 个点的有根树 T 1 T_1 T1​, T 2 T_2 T2​,根是 1 1 1 ,共用编号 1 1 1~ n n n.求最大的点集 S S S 满足每个点在 T 1 T_1 ...

  8. IO流----读取文件,复制文件,追加/插入文件

    文件结构 读取文件 第一种方式 public class Test { public static void main(String[] args) throws IOException { // 最 ...

  9. Spring(四)-声明式事务

    Spring-04 声明式事务 1.事务的定义 事务就是由一组逻辑上紧密关联的多个工作单元(数据库操作)而合并成一个整体,这些操作要么都执行,要么都不执行. 2.事务的特性:ACID 1)原子性A : ...

  10. 第五十三篇:Vue安装Element ui

    好家伙,之前写的一篇过时了,用不了了,更新一波 (已新建一个vue项目) 1. 在项目目录下执行:npm i element-ui -S 2. 在main.js中写入 import ElementUI ...