Skip to content

Commit

Permalink
feat: add Monolithic Application example, including frontend and back…
Browse files Browse the repository at this point in the history
…end.
  • Loading branch information
tx7do committed Jan 15, 2024
1 parent b1ea527 commit b88abf5
Show file tree
Hide file tree
Showing 871 changed files with 137,563 additions and 42 deletions.
57 changes: 29 additions & 28 deletions README-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,31 +2,32 @@

[English](README.md) | 简体中文

| 项目名 | 说明 |
|------------------------------|----------------------------------|
| [auth/jwt](./auth/jwt) | JWT使用示例 |
| [blog](./blog) | 博客系统,简单的CRUD示例 |
| [casbin](./casbin) | JWT认证和Casbin鉴权的示例 |
| [chatroom](./chatroom) | 最简单的Websocket聊天室示例 |
| [config](./config) | 文件配置和远程配置中心使用示例 |
| [cqrs](./cqrs) | CQRS模式实现示例,主要是Kafka的使用。 |
| [errors](./errors) | 错误处理示例 |
| [event](./event) | 使用Kafka等MQ收发消息示例 |
| [header](./header) | 自定义HTTP的Header示例 |
| [helloworld](./helloworld) | RPC调用示例 |
| [http](./http) | HTTP相关应用的示例,如:CORS、上传文件等。 |
| [i18n](./i18n) | 国际化与本地化的示例 |
| [log](./log) | 日志使用示例 |
| [metadata](./metadata) | 元数据使用示例 |
| [metrics](./metrics) | 度量系统使用示例 |
| [middleware](./middleware) | 中间件使用示例 |
| [realtimemap](./realtimemap) | 实时公交地图,主要是MQTT、Websocket、RPC综合使用 |
| [registry](./registry) | 注册中心使用示例 |
| [selector](./selector) | 节点选择器使用示例 |
| [stream](./stream) | |
| [swagger](./swagger) | swagger api使用示例 |
| [tls](./tls) | TLS证书使用示例 |
| [traces](./traces) | 链路追踪系统使用示例 |
| [transaction](./transaction) | 数据库事务使用示例 |
| [validate](./validate) | Protobuf参数校验器使用示例 |
| [ws](./ws) | 最简单的Websocket示例 |
| 项目名 | 说明 |
| ---------------------------- | -------------------------------------------------- |
| [auth/jwt](./auth/jwt) | JWT 使用示例 |
| [blog](./blog) | 博客系统,简单的 CRUD 示例 |
| [casbin](./casbin) | JWT 认证和 Casbin 鉴权的示例 |
| [chatroom](./chatroom) | 最简单的 Websocket 聊天室示例 |
| [config](./config) | 文件配置和远程配置中心使用示例 |
| [cqrs](./cqrs) | CQRS 模式实现示例,主要是 Kafka 的使用。 |
| [errors](./errors) | 错误处理示例 |
| [event](./event) | 使用 Kafka 等 MQ 收发消息示例 |
| [header](./header) | 自定义 HTTP 的 Header 示例 |
| [helloworld](./helloworld) | RPC 调用示例 |
| [http](./http) | HTTP 相关应用的示例,如:CORS、上传文件等。 |
| [i18n](./i18n) | 国际化与本地化的示例 |
| [log](./log) | 日志使用示例 |
| [metadata](./metadata) | 元数据使用示例 |
| [metrics](./metrics) | 度量系统使用示例 |
| [middleware](./middleware) | 中间件使用示例 |
| [realtimemap](./realtimemap) | 实时公交地图,主要是 MQTT、Websocket、RPC 综合使用 |
| [registry](./registry) | 注册中心使用示例 |
| [selector](./selector) | 节点选择器使用示例 |
| [stream](./stream) | |
| [swagger](./swagger) | swagger api 使用示例 |
| [tls](./tls) | TLS 证书使用示例 |
| [traces](./traces) | 链路追踪系统使用示例 |
| [transaction](./transaction) | 数据库事务使用示例 |
| [validate](./validate) | Protobuf 参数校验器使用示例 |
| [ws](./ws) | 最简单的 Websocket 示例 |
| [monolithic](./monolithic) | 巨石系统(单体系统)应用实例,包含前后端。 |
44 changes: 30 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,17 +1,33 @@
# examples
# Kratos examples

English | [简体中文](README-CN.md)

- blog is simple crud project.
- config is kratos config example.
- errors is kratos errors example, it is generated through proto-gen-go-errors.
- helloworld is helloworld example.
- http is transport/http some examples of usage.
- log is log example, including、logger、helper、filter、valuer, etc.
- metadata is metadata example.
- metrics is metrics example, in the example, prom is used to collect data.
- registry is registration and discovery examples,including Etcd, Consul, Nacos.
- traces is middleware/tracing example,middleware/tracing is implemented by opentelemetry.
- validate is middleware/validate example, the verification code is generated by proto-gen-validate.
- ws is implementation of transport interface with websocket example.
- swagger is implementation of server with embed swagger api.
| Project Name | Description |
| ---------------------------- | ----------------------------------------------------------------------- |
| [auth/jwt](./auth/jwt) | Examples of JWT usage |
| [blog](./blog) | Blog system, simple CRUD example |
| [casbin](./casbin) | Examples of JWT authentication and Casbin authentication |
| [chatroom](./chatroom) | The simplest Websocket chat room example |
| [config](./config) | Examples of file configuration and remote configuration Center usage |
| [cqrs](./cqrs) | Examples of CQRS pattern implementation, mainly the use of Kafka. |
| [errors](./errors) | Error handling example |
| [event](./event) | Example of sending and receiving messages using MQ like Kafka |
| [header](./header) | Example of a custom HTTP Header |
| [helloworld](./helloworld) | RPC Call example |
| [http](./http) | Examples of HTTP-related applications, such as CORS and uploading files |
| [i18n](./i18n) | Examples of internationalization and localization |
| [log](./log) | Log usage example |
| [metadata](./metadata) | Examples of metadata usage |
| [metrics](./metrics) | Measurement system usage examples |
| [middleware](./middleware) | Middleware usage Examples |
| [realtimemap](./realtimemap) | Real-time bus map, mainly MQTT, Websocket, RPC integrated use |
| [registry](./registry) | Registry center usage examples |
| [selector](./selector) | Examples of node selector usage |
| [stream](./stream) | |
| [swagger](./swagger) | swagger is implementation of server with embed swagger api |
| [tls](./tls) | Example of TLS certificate usage |
| [traces](./traces) | Example of Distributed Tracing system |
| [transaction](./transaction) | Sample database transaction usage |
| [validate](./validate) | Example of Protobuf parameter validator usage |
| [ws](./ws) | ws is implementation of transport interface with websocket example |
| [monolithic](./monolithic) | Monolithic Application example, including frontend and backends. |
21 changes: 21 additions & 0 deletions monolithic/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# If you prefer the allow list template instead of the deny list, see community template:
# https://github.com/github/gitignore/blob/main/community/Golang/Go.AllowList.gitignore
#
# Binaries for programs and plugins
*.exe
*.exe~
*.dll
*.so
*.dylib

# Test binary, built with `go test -c`
*.test

# Output of the go coverage tool, specifically when used with LiteIDE
*.out

# Dependency directories (remove the comment below to include it)
# vendor/

# Go workspace file
go.work
21 changes: 21 additions & 0 deletions monolithic/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2023 Bobo

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
4 changes: 4 additions & 0 deletions monolithic/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Golang微服务框架Kratos的巨石应用实践

- 后端基于 golang微服务框架 [go-kratos](https://go-kratos.dev/)
- 前端基于 [VUE3](https://vuejs.org/) + [TypeScript](https://www.typescriptlang.org/)
35 changes: 35 additions & 0 deletions monolithic/backend/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# Reference https://github.com/github/gitignore/blob/master/Go.gitignore
# Binaries for programs and plugins
*.exe
*.exe~
*.dll
*.so
*.dylib

# Test binary, built with `go test -c`
*.test

# Output of the go coverage tool, specifically when used with LiteIDE
*.out

# Dependency directories (remove the comment below to include it)
vendor/

# Compiled Object files, Static and Dynamic libs (Shared Objects)
*.o
*.a

# OS General
Thumbs.db
.DS_Store

# project
*.cert
*.key
*.log
bin/

# Develop tools
.vscode/
.idea/
*.swp
4 changes: 4 additions & 0 deletions monolithic/backend/.markdownlint.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
---
line-length: false
no-hard-tabs: false
no-inline-html: false
10 changes: 10 additions & 0 deletions monolithic/backend/.yamllint
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# vim: ft=yaml
---
yaml-files:
- "*.yaml"
- "*.yml"
- ".yamllint"
extends: "default"
rules:
quoted-strings: "enable"
line-length: "disable"
95 changes: 95 additions & 0 deletions monolithic/backend/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
# Not Support Windows

.PHONY: help wire gen ent build api openapi init all

ifeq ($(OS),Windows_NT)
IS_WINDOWS:=1
endif

CURRENT_DIR := $(patsubst %/,%,$(dir $(abspath $(lastword $(MAKEFILE_LIST)))))
ROOT_DIR := $(dir $(realpath $(lastword $(MAKEFILE_LIST))))

SRCS_MK := $(foreach dir, app, $(wildcard $(dir)/*/*/Makefile))

# initialize develop environment
init: plugin cli

# install protoc plugin
plugin:
@go install google.golang.org/protobuf/cmd/protoc-gen-go@latest
@go install google.golang.org/grpc/cmd/protoc-gen-go-grpc@latest
@go install github.com/go-kratos/kratos/cmd/protoc-gen-go-http/v2@latest
@go install github.com/go-kratos/kratos/cmd/protoc-gen-go-errors/v2@latest
@go install github.com/grpc-ecosystem/grpc-gateway/v2/protoc-gen-openapiv2@latest
@go install github.com/google/gnostic/cmd/protoc-gen-openapi@latest
@go install github.com/envoyproxy/protoc-gen-validate@latest

# install cli tools
cli:
@go install github.com/go-kratos/kratos/cmd/kratos/v2@latest
@go install github.com/google/gnostic@latest
@go install github.com/bufbuild/buf/cmd/buf@latest
@go install entgo.io/ent/cmd/ent@latest
@go install github.com/golangci/golangci-lint/cmd/golangci-lint@latest

# generate wire code
wire:
$(foreach dir, $(dir $(realpath $(SRCS_MK))),\
cd $(dir);\
make wire;\
)

# generate code by go:generate
gen:
$(foreach dir, $(dir $(realpath $(SRCS_MK))),\
cd $(dir);\
make gen;\
)

# generate ent code
ent:
$(foreach dir, $(dir $(realpath $(SRCS_MK))),\
cd $(dir);\
make ent;\
)

# generate protobuf api go code
api:
buf generate

# generate OpenAPI v3 docs.
openapi:
buf generate --path api/admin/service/v1 --template api/admin/service/v1/buf.openapi.gen.yaml

# build all service applications
build:
$(foreach dir, $(dir $(realpath $(SRCS_MK))),\
cd $(dir);\
make build;\
)

# generate & build all service applications
all:
$(foreach dir, $(dir $(realpath $(SRCS_MK))),\
cd $(dir);\
make app;\
)

# show help
help:
@echo ""
@echo "Usage:"
@echo " make [target]"
@echo ""
@echo 'Targets:'
@awk '/^[a-zA-Z\-_0-9]+:/ { \
helpMessage = match(lastLine, /^# (.*)/); \
if (helpMessage) { \
helpCommand = substr($$1, 0, index($$1, ":")-1); \
helpMessage = substr(lastLine, RSTART + 2, RLENGTH); \
printf "\033[36m%-22s\033[0m %s\n", helpCommand,helpMessage; \
} \
} \
{ lastLine = $$0 }' $(MAKEFILE_LIST)

.DEFAULT_GOAL := help
89 changes: 89 additions & 0 deletions monolithic/backend/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
# GO后端

## API文档

### Swagger UI

- [Admin Swagger UI](http://localhost:7788/docs/)

### openapi.yaml

- [Admin openapi.yaml](http://localhost:7788/docs/openapi.yaml)

## Buf.Build使用

使用[buf.build](https://buf.build/)进行Protobuf API的工程化构建。

相关命令行工具和插件的具体安装方法请参见:[Kratos微服务框架API工程化指南](https://juejin.cn/post/7191095845096259641)

`backend`根目录下执行命令:

### 更新buf.lock

```bash
buf mod update
```

### 生成GO代码

```bash
buf generate
```

### 生成OpenAPI v3文档

```bash
buf generate --path api/admin/service/v1 --template api/admin/service/v1/buf.openapi.gen.yaml
```

## Make构建

请在`app/{服务名}/service`下执行:

### 初始化开发环境

```bash
make init
```

### 生成API的go代码

```bash
make api
```

### 生成API的OpenAPI v3 文档

```bash
make openapi
```

### 生成ent代码

```bash
make ent
```

### 生成wire代码

```bash
make wire
```

### 构建程序

```bash
make build
```

### 调试运行

```bash
make run
```

### 构建Docker镜像

```bash
make docker
```
Loading

0 comments on commit b88abf5

Please sign in to comment.