GO框架三件套 | 青训营

94 阅读1分钟

GO框架三件套分别是Gorm、Kitex、Hertz

  • grom: Gorm是—个已经迭代了10年+的功能强大的ORM框架,在字节内部被广泛使用并且拥有非常丰富的开源扩展。
  • kitex: Kitex是字节内部的Golang微服务RPC框架,具有高性能、强可扩展的主要特点,支持多协议并且拥有丰富的开源扩展。
  • hertz: Hertz是字节内部的HTTP框架,参考了其他开源框架的优势,结合字节跳动内部的需求,具有高易用性、高性能、高扩展性特点。

一、Gorm

GORM 指南 | GORM - The fantastic ORM library for Golang, aims to be developer friendly.

1.1 Gorm的基本使用

image.png Gorm的约定(默认)

  1. Gorm使用名为ID的字段作为主键
  2. 使用结构体的蛇形负数作为表名
  3. 使用结构体的蛇形负数作为表名
  4. 使用CreatedAt、UpdatedAt字段作为创建、更新时间

1.2 Gorm支持的数据库

GORM目前支持MySQL、SQLServer、PostgreSQL、SQLite。
GORM通过驱动来连接数据库,如果需要连接其它类型的数据库,可以复用/自行开发驱动。

image.png

1.3 Gorm创建数据

image.png

1.4 Gorm查询数据

image.png

1.5 Gorm更新数据

image.png

1.6 Gorm删除数据

image.png

1.7 Gorm事务

image.png

image.png

1.8 Gorm Hook

image.png

1.9 Gorm性能提升

image.png

1.10 Gorm生态

image.png

二、Kitex

快速开始 | CloudWeGo

2.1 安装Kitex代码生成工具

image.png

2.2 定义IDL

image.png

2.3 Kitex生成代码

image.png

2.4 Kitex基础使用

image.png

2.5 Kitex Client发起请求

image.png

2.6 Kitex服务注册与发现

image.png

image.png

2.7 Kitex生态

image.png

三、Hertz

快速开始 | CloudWeGo

3.1 Hertz基本使用

image.png

3.2 Hertz路由

image.png

image.png

image.png

image.png

3.3 Hertz中间件

image.png

3.4 Hertz CLient

image.png

3.5 Hertz 代码生成工具

image.png

image.png

3.6 提升Hertz性能

  1. 使用网络库Netpoll
  2. Json编解码 Sonic
  3. 使用sync.Pool复用对象协议层数据解析优化

3.7 Hertz生态

image.png

四、EasyNote实践项目

kitex-examples/bizdemo/easy_note at main · cloudwego/kitex-examples (github.com)