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. Docker Compose之容器编排开发初探

    1.前言 Docker Compose 是 Docker 官方编排(Orchestration)项目之一,负责快速在集群中部署分布式应用. Compose 是一个用于定义和运行多个 Docker 应用 ...

  2. Little Girl and Problem on Trees

    题意 给定一棵无边权的树,最多只有一个点度数超过2,有两种操作 1)(0 u x d)将距离u节点d距离之内的节点的值加上x 2)(1 u)询问u节点的值 n<=100000,q<=100 ...

  3. 100 个常见错误「GitHub 热点速览 v.22.35」

    本周的特推非常得延续上周的特点--会玩,向别人家的女朋友发送早安.这个错误是如何发生的呢?如何有效避免呢?自己用 daily_morning 免部署.定制一个早安小助手给女友吧. 除了生活中的错误,工 ...

  4. c语言_二叉树的建立以及3种递归

    二叉树c语言的实现 二叉树的建立 二叉树的数据结构 typedef struct node{    int data;    struct node* left;    struct node* ri ...

  5. KingbaseES V8R6C5 通过securecmdd工具手工脚本部署集群

    案例说明: 对于KingbaseES V8R6C5版本在部集群时,需要建立kingbase.root用户在节点间的ssh互信,如果在生产环境禁用root用户ssh登录,则通过ssh部署会失败:V8R6 ...

  6. CDH6.2.0 搭建大数据集群

    1. 资料准备 现在官网https://www.cloudera.com 需要注册账号,未来可能会收费等问题,十分麻烦,这里有一份我自己百度云的备份 链接: https://pan.baidu.com ...

  7. PHP之旅---出发(php+apache+MySQL)

    @ 目录 前言 准备 php安装 Apache安装 MySQL安装 Navicat安装(附) Apache+php整合 验证Apache+php 前言 本文详细介绍php+apache+MySQL在w ...

  8. PHP使用ZipArchive压缩、解压缩、加密压缩包等

    <?php use ZipArchive; class Zip { /** * @var array $files 需要压缩的文件或文件夹 */ public $files = []; /** ...

  9. 使用kubeoperator安装的k8s集群配置Ingress规则有关说明

    单独创建一个nginx 在 Deployment 里创建一个nginx工作负载,镜像用:nginx:alpine,并配置service为ClusterIP,然后添加Ingress规则 本地主机host ...

  10. Docker 部署 RocketMQ 双主双从模式( 版本v4.7.0)

    文章转载自:http://www.mydlq.club/article/96/ 系统环境: 系统版本:CentOS 7.8 RocketMQ 版本:4.7.0 Docker 版本:19.03.13 一 ...