Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add sample_douyin demo #40

Open
wants to merge 20 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions sample_douyin/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
*.mp4
*.jpg
# *.sh
# pkg/consts/consts.go
.idea
cmd/user/output/bin/douyinuser
cmd/favorite/output/bin/favorite
cmd/comment/output/bin/comment
cmd/relation/output/bin/relation
cmd/user/output/bin/douyinuser
cmd/message/output/bin/message
23 changes: 23 additions & 0 deletions sample_douyin/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
install_kitex_latest:
go install github.com/cloudwego/kitex/tool/cmd/kitex@latest

install_thriftgo:
go install github.com/cloudwego/thriftgo

kitex_gen_user:
kitex --thrift-plugin validator -module github.com/cloudwego/biz-demo/sample_douyin idl/user.thrift # execute in the project root directory

kitex_gen_video:
kitex --thrift-plugin validator -module github.com/cloudwego/biz-demo/sample_douyin idl/video.thrift # execute in the project root directory

kitex_gen_relation:
kitex --thrift-plugin validator -module github.com/cloudwego/biz-demo/sample_douyin idl/relation.thrift # execute in the project root directory

kitex_gen_message:
kitex --thrift-plugin validator -module github.com/cloudwego/biz-demo/sample_douyin idl/message.thrift # execute in the project root directory

kitex_gen_favorite:
kitex --thrift-plugin validator -module github.com/cloudwego/biz-demo/sample_douyin idl/favorite.thrift # execute in the project root directory

kitex_gen_comment:
kitex --thrift-plugin validator -module github.com/cloudwego/biz-demo/sample_douyin idl/comment.thrift # execute in the project root directory
154 changes: 154 additions & 0 deletions sample_douyin/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,154 @@
# Sample Douyin

## Introduction
A simple Douyin service built with `Kitex` and `Hertz` which is divided into seven microservices.

| Service Name | Usage | Framework | protocol | Path | IDL |
|--------------|--------------------------|-------------|----------|--------------|---------------------|
| api | HTTP interface | kitex/hertz | http | cmd/api | idl/api.thrift |
| user | user data management | kitex/gorm | thrift | cmd/user | idl/user.thrift |
| video | video data management | kitex/gorm | thrift | cmd/video | idl/video.thrift |
| favorite | favorite data management | kitex/gorm | thrift | cmd/favorite | idl/favorite.thrift |
| comment | comment data management | kitex/gorm | thrift | cmd/comment | idl/comment.thrift |
| message | message data management | kitex/gorm | thrift | cmd/message | idl/message.thrift |
| relation | relation data management | kitex/gorm | thrift | cmd/relation | idl/relation.thrift |

### Architecture

![Architecture](./images/architecture.jpg)

### Call Relations

![Call Relations](./images/call-relation.jpg)

### Basic Features

- Hertz
- Use `Hertz` binding and validate
- Use `obs-opentelemetry` and `jarger` for `tracing`, `metrics`, `logging`
- Middleware
- Use `requestid`, `jwt`, `recovery`, `gzip`
- Kitex
- User `thrift` IDL to define `RPC` interface
- Use `kitex` to generate code
- Use `obs-opentelemetry` and `jarger` for `tracing`, `metrics`, `logging`
- Use `registry-etcd` for service discovery and register

### Catalog Introduce

| catalog | introduce |
|---------------|-------------------------|
| handler | HTTP handler |
| service | business logic |
| rpc | RPC call logic |
| dal | DB operation |
| pack | data pack |
| apimodel | struct definition |
| cache | Redis operation |
| videoHandler | Video stream processing |
| pkg/mw | RPC middleware |
| pkg/consts | constants |
| pkg/errno | customized error number |
| pkg/configs | SQL and Tracing configs |

## Code Generation

| catalog | command |
|-----------------------|--------------------------------------|
| kitex_user_client | make kitex_gen_user |
| kitex_video_client | make kitex_gen_video |
| kitex_favorite_client | make kitex_gen_favorite |
| kitex_comment_client | make kitex_gen_comment |
| kitex_message_client | make kitex_gen_message |
| kitex_relation_client | make kitex_gen_relation |
| kitex_user_server | cd cmd/user && make kitex_gen_server |
| kitex_video_server | cd cmd/video && make kitex_gen_server |
| kitex_favorite_server | cd cmd/favorite && make kitex_gen_server |
| kitex_comment_server | cd cmd/comment && make kitex_gen_server |
| kitex_message_server | cd cmd/message && make kitex_gen_server |
| kitex_relation_server | cd cmd/relation && make kitex_gen_server |

## Quick Start

### Setup Basic Dependence

```shell
docker-compose up -d
```

### Change config
Edit the following code block in pkg/consts/consts.go and replace it with your own Alibaba Cloud OSS AKID & AKS etc.
```go
Endpoint = "oss-c**************cs.com"
AKID = "LTAI****************92kxo"
AKS = "SmEa**************LuS9N3K9"
Bucket = "douy******************67"
CDNURL = "http://*************.cn/"
```

### Run User RPC Server

```shell
cd cmd/user
sh build.sh
sh output/bootstrap.sh
```

### Run Video RPC Server

```shell
cd cmd/video
sh build.sh
sh output/bootstrap.sh
```

### Run Relation RPC Server

```shell
cd cmd/relation
sh build.sh
sh output/bootstrap.sh
```

### Run Favorite RPC Server

```shell
cd cmd/favorite
sh build.sh
sh output/bootstrap.sh
```

### Run Comment RPC Server

```shell
cd cmd/comment
sh build.sh
sh output/bootstrap.sh
```
### Run Message RPC Server

```shell
cd cmd/message
sh build.sh
sh output/bootstrap.sh
```
### Run API Server

```shell
cd cmd/api
go run .
```
### Jaeger

Visit `http://127.0.0.1:16686/` on browser

### Grafana

Visit `http://127.0.0.1:3000/` on browser

### APK

[:memo:Sample Douyin APP Package Instructions](https://bytedance.feishu.cn/docs/doccnM9KkBAdyDhg8qaeGlIz7S7#quPkfu)

## [:point_right: MORE](https://a6i0rzkzjm.feishu.cn/docx/Xa8sdTIGJopWrNxYgeVcrmxPnKe#doxcnPDVQrEZq14hwckf1K1Taqg)

37 changes: 37 additions & 0 deletions sample_douyin/cmd/api/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
*.o
*.a
*.so
_obj
_test
*.[568vq]
[568vq].out
*.cgo1.go
*.cgo2.c
_cgo_defun.c
_cgo_gotypes.go
_cgo_export.*
_testmain.go
*.exe
*.exe~
*.test
*.prof
*.rar
*.zip
*.gz
*.psd
*.bmd
*.cfg
*.pptx
*.log
*nohup.out
*settings.pyc
*.sublime-project
*.sublime-workspace
!.gitkeep
.DS_Store
/.idea
/.vscode
/output
*.local.yml
dumped_hertz_remote_config.json

3 changes: 3 additions & 0 deletions sample_douyin/cmd/api/.hz
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// Code generated by hz. DO NOT EDIT.

hz version: v0.5.1
Loading