• Stars
    star
    109
  • Rank 318,048 (Top 7 %)
  • Language
    Go
  • Created over 3 years ago
  • Updated about 2 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

从 protobuf 文件中生成使用 gin 的 http rpc 服务 (protobuf to gin code)

protoc-gen-go-gin

修改自 kratos v2

从 protobuf 文件中生成使用 gin 的 http rpc 服务

安装

请确保安装了以下依赖:

注意由于使用 embed 特性,Go 版本必须大于 1.16

go install github.com/mohuishou/protoc-gen-go-gin@latest

使用说明

例子见: example

proto 文件约定

默认情况下 rpc method 命名为 方法+资源,使用驼峰方式命名,生成代码时会进行映射

方法映射方式如下所示:

  • "GET", "FIND", "QUERY", "LIST", "SEARCH" --> GET
  • "POST", "CREATE" --> POST
  • "PUT", "UPDATE" --> PUT
  • "DELETE" --> DELETE
service BlogService {
  rpc CreateArticle(Article) returns (Article) {}
  // 生成 http 路由为 post: /article
}

除此之外还可以使用 google.api.http option 指定路由,可以通过添加 additional_bindings 使一个 rpc 方法对应多个路由

// blog service is a blog demo
service BlogService {
  rpc GetArticles(GetArticlesReq) returns (GetArticlesResp) {
    // 
    // 可以通过添加 additional_bindings 使一个 rpc 方法对应多个路由
    option (google.api.http) = {
      get: "/v1/articles"
      additional_bindings {
        get: "/v1/author/{author_id}/articles"
      }
    };
  }
}

文件生成

  protoc -I ./example/api \
  --go_out ./example/api --go_opt=paths=source_relative \
  --go-gin_out ./example/api --go-gin_opt=paths=source_relative \
  example/api/product/app/v1/v1.proto

相关介绍

待发布

  • Go工程化(四) API 设计上: 项目结构 & 设计
  • Go工程化(五) API 设计下: 基于 protobuf 自动生成 gin 代码

More Repositories

1

go-design-pattern

golang design pattern go 设计模式实现,包含 23 种常见的设计模式实现,同时这也是极客时间-设计模式之美 的笔记
Go
1,924
star
2

scuplus-wechat

We川大小程序[scuplus] 使用wepy开发的完善的校园综合小程序, 40+页面,前后端开源,包括成绩、课表、失物招领、图书馆、新闻资讯等等常见校园场景功能
Vue
665
star
3

utools

utools 插件,utools api, chrome历史记录搜索、vscode历史项目搜索、otp两步验证,iconfont图标搜索下载、语雀搜索等
TypeScript
291
star
4

ImageOCR

PHP验证码识别[PHP CAPTCHA Recognition]
PHP
271
star
5

scuplus-go

We川大小程序后端
Go
105
star
6

blog-code

https://lailin.xyz 博客代码
Go
39
star
7

PaperDownload

知网/万方 论文/期刊批量检索下载
Go
24
star
8

go-algorithm

【更新中】Go 数据结构与算法系列文章,本系列文章主要会包括常见的数据结构与算法实现,同时会包括 Go 标准库代码的分析理解,讲到对应章节的时候优先学习分析 Go 的源码实现,例如 slice、list、sort 等,然后可能会有一些常见的案例实现,同时这也是 极客时间-数据结构与算法之美 的课程笔记
Go
21
star
9

siyuan-sync-github

思源笔记挂件块,同步 markdown 笔记文件为 到 github,支持迁移笔记到图床
TypeScript
19
star
10

notion-blog-actions

convert notion database pages to markdown files for hexo or hugo
JavaScript
18
star
11

ATool

通过调用安卓加速度传感器,绘制曲线图,导出为文本文件,并且计算交通工具的舒适程度
Java
15
star
12

cet

免证四六级查询
C
14
star
13

gen-const-msg

提取源码文件中的常量注释,生成对应的 msg 信息,常用于err code当中
Go
11
star
14

wxapp-schedule

小程序课程表组件
JavaScript
9
star
15

mohuishou.github.io

Mohuishou's Blog
HTML
9
star
16

apollo-viper-provider

use ctripcorp/apollo as viper's RemoteConfigProvider
Go
9
star
17

go-sort

常用排序算法的golang实现
Go
6
star
18

php-webhook

git自动部署钩子
PHP
6
star
19

mohuishou

Go
5
star
20

goDataStruct

中国大学MOOC数据结构课程学习
Go
4
star
21

autoSign

联通沃贝相关自动签到包
PHP
3
star
22

monitor

web服务监控
Go
3
star
23

sms-notice

短信通知系统
PHP
3
star
24

typecho2hexo

转换typecho数据为hexo格式的md文件,支持附件(图片)下载,附件(图片)上传到七牛
PHP
3
star
25

evaluate-go

四川大学快捷评教
Vue
2
star
26

hugo-action

use github action with hugo
Shell
2
star
27

BabyBuddy-Baby

婴儿智能监护系统app婴儿端,前端。采用appcan平台开发
HTML
1
star
28

leetcode

1
star
29

email

邮件后台发送服务
Go
1
star
30

cloudbase-siyuan-note

使用 腾讯云 云开发一键部署 思源笔记
Python
1
star
31

resume

个人简历
1
star
32

go-test-multi-module

在单个仓库中支持多个 go mod 模块示例
Go
1
star
33

swugpa

西南大学绩点/平均分一键计算
PHP
1
star
34

yzdesign

yzdesign for phpwind
PHP
1
star