Skip to content

Commit 72e718a

Browse files
committed
feat: add ent curd examples for ent and gorm.
1 parent b88abf5 commit 72e718a

File tree

264 files changed

+58500
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

264 files changed

+58500
-0
lines changed

README-CN.md

+2
Original file line numberDiff line numberDiff line change
@@ -31,3 +31,5 @@
3131
| [validate](./validate) | Protobuf 参数校验器使用示例 |
3232
| [ws](./ws) | 最简单的 Websocket 示例 |
3333
| [monolithic](./monolithic) | 巨石系统(单体系统)应用实例,包含前后端。 |
34+
| [ent orm](./orm/ent/) | Ent 的 CURD 完整应用实例。 |
35+
| [gorm](./monolithic) | GORM 的 CURD 完整应用实例。 |

README.md

+2
Original file line numberDiff line numberDiff line change
@@ -31,3 +31,5 @@ English | [简体中文](README-CN.md)
3131
| [validate](./validate) | Example of Protobuf parameter validator usage |
3232
| [ws](./ws) | ws is implementation of transport interface with websocket example |
3333
| [monolithic](./monolithic) | Monolithic Application example, including frontend and backends. |
34+
| [ent orm](./orm/ent/) | CURD full application example of Ent. |
35+
| [gorm](./monolithic) | CURD full application example of GORM. |

orm/ent/.gitignore

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# If you prefer the allow list template instead of the deny list, see community template:
2+
# https://github.com/github/gitignore/blob/main/community/Golang/Go.AllowList.gitignore
3+
#
4+
# Binaries for programs and plugins
5+
*.exe
6+
*.exe~
7+
*.dll
8+
*.so
9+
*.dylib
10+
11+
# Test binary, built with `go test -c`
12+
*.test
13+
14+
# Output of the go coverage tool, specifically when used with LiteIDE
15+
*.out
16+
17+
# Dependency directories (remove the comment below to include it)
18+
# vendor/
19+
20+
# Go workspace file
21+
go.work

orm/ent/LICENSE

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2023 Bobo
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

orm/ent/Makefile

+80
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
# Not Support Windows
2+
3+
.PHONY: help wire conf ent build api openapi init all
4+
5+
ifeq ($(OS),Windows_NT)
6+
IS_WINDOWS:=1
7+
endif
8+
9+
CURRENT_DIR := $(patsubst %/,%,$(dir $(abspath $(lastword $(MAKEFILE_LIST)))))
10+
ROOT_DIR := $(dir $(realpath $(lastword $(MAKEFILE_LIST))))
11+
12+
SRCS_MK := $(foreach dir, app, $(wildcard $(dir)/*/*/Makefile))
13+
14+
# generate wire code
15+
wire:
16+
$(foreach dir, $(dir $(realpath $(SRCS_MK))),\
17+
cd $(dir);\
18+
make wire;\
19+
)
20+
21+
# generate config define code
22+
conf:
23+
$(foreach dir, $(dir $(realpath $(SRCS_MK))),\
24+
cd $(dir);\
25+
make conf;\
26+
)
27+
28+
# generate ent code
29+
ent:
30+
$(foreach dir, $(dir $(realpath $(SRCS_MK))),\
31+
cd $(dir);\
32+
make ent;\
33+
)
34+
35+
# generate protobuf api go code
36+
api:
37+
buf generate
38+
39+
# generate OpenAPI v3 docs.
40+
openapi:
41+
buf generate --path api/admin/service/v1 --template api/admin/service/v1/buf.openapi.gen.yaml
42+
buf generate --path api/front/service/v1 --template api/front/service/v1/buf.openapi.gen.yaml
43+
44+
# initialize develop environment
45+
init:
46+
cd $(lastword $(dir $(realpath $(SRCS_MK))));\
47+
make init;
48+
49+
# build all service applications
50+
build:
51+
$(foreach dir, $(dir $(realpath $(SRCS_MK))),\
52+
cd $(dir);\
53+
make build;\
54+
)
55+
56+
# generate & build all service applications
57+
all:
58+
$(foreach dir, $(dir $(realpath $(SRCS_MK))),\
59+
cd $(dir);\
60+
make app;\
61+
)
62+
63+
# show help
64+
help:
65+
@echo ""
66+
@echo "Usage:"
67+
@echo " make [target]"
68+
@echo ""
69+
@echo 'Targets:'
70+
@awk '/^[a-zA-Z\-_0-9]+:/ { \
71+
helpMessage = match(lastLine, /^# (.*)/); \
72+
if (helpMessage) { \
73+
helpCommand = substr($$1, 0, index($$1, ":")-1); \
74+
helpMessage = substr(lastLine, RSTART + 2, RLENGTH); \
75+
printf "\033[36m%-22s\033[0m %s\n", helpCommand,helpMessage; \
76+
} \
77+
} \
78+
{ lastLine = $$0 }' $(MAKEFILE_LIST)
79+
80+
.DEFAULT_GOAL := help

orm/ent/README.md

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# Kratos Ent ORM实例

orm/ent/WORKSPACE

+143
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,143 @@
1+
# gazelle:repo bazel_gazelle
2+
workspace(name = "com_github_tx7do_kratos_blog")
3+
4+
#########################################
5+
## 下载所需要的软件包
6+
#########################################
7+
8+
load("//:DOWNLOAD.bzl", "download_package")
9+
10+
download_package()
11+
12+
#########################################
13+
## Bazel Go语言 规则集 初始化
14+
#########################################
15+
16+
load("@io_bazel_rules_go//go:deps.bzl", "go_register_toolchains", "go_rules_dependencies")
17+
18+
go_rules_dependencies()
19+
20+
go_register_toolchains(version = "1.19.5")
21+
22+
#########################################
23+
## Bazel Gazelle 规则集 初始化
24+
#########################################
25+
26+
load("@bazel_gazelle//:deps.bzl", "gazelle_dependencies")
27+
load("//:repos.bzl", "go_dependencies")
28+
29+
# gazelle:repository_macro repos.bzl%go_dependencies
30+
go_dependencies()
31+
32+
gazelle_dependencies()
33+
34+
#########################################
35+
## Bazel Docker 规则集 初始化
36+
#########################################
37+
38+
load(
39+
"@io_bazel_rules_docker//repositories:repositories.bzl",
40+
container_repositories = "repositories",
41+
)
42+
43+
container_repositories()
44+
45+
load("@io_bazel_rules_docker//repositories:deps.bzl", container_deps = "deps")
46+
47+
container_deps()
48+
49+
load("@io_bazel_rules_docker//container:pull.bzl", "container_pull")
50+
51+
# 拉取Alpine Linux
52+
# 该发行版使用musl libc,并且缺乏一些调试工具。
53+
container_pull(
54+
name = "alpine_linux_amd64",
55+
registry = "index.docker.io",
56+
repository = "library/alpine",
57+
tag = "latest",
58+
)
59+
60+
# 拉取Debian-Slim Linux
61+
container_pull(
62+
name = "slim_linux_amd64",
63+
registry = "index.docker.io",
64+
repository = "library/debian",
65+
tag = "stable-slim",
66+
)
67+
68+
# 拉取Centos Linux
69+
container_pull(
70+
name = "centos_linux_amd64",
71+
registry = "index.docker.io",
72+
repository = "library/centos",
73+
tag = "7",
74+
)
75+
76+
# 拉取Ubuntu Linux
77+
container_pull(
78+
name = "ubuntu_linux_amd64",
79+
registry = "index.docker.io",
80+
repository = "library/ubuntu",
81+
tag = "latest",
82+
)
83+
84+
#########################################
85+
## Bazel Kubernetes 规则集 初始化
86+
#########################################
87+
88+
load("@io_bazel_rules_k8s//k8s:k8s.bzl", "k8s_repositories")
89+
90+
k8s_repositories()
91+
92+
#########################################
93+
## Bazel pkg 规则集 初始化
94+
#########################################
95+
96+
load("@rules_pkg//:deps.bzl", "rules_pkg_dependencies")
97+
98+
rules_pkg_dependencies()
99+
100+
#########################################
101+
## Bazel protoc 初始化
102+
#########################################
103+
104+
load("@com_google_protobuf//:protobuf_deps.bzl", "protobuf_deps")
105+
106+
protobuf_deps()
107+
108+
#########################################
109+
## Bazel Buf 规则集 初始化
110+
#########################################
111+
112+
# load("@rules_buf//buf:repositories.bzl", "rules_buf_dependencies", "rules_buf_toolchains")
113+
# load("@rules_buf//gazelle/buf:repositories.bzl", "gazelle_buf_dependencies")
114+
# load("//:buf_deps.bzl", "buf_deps")
115+
116+
# # gazelle:repository_macro buf_deps.bzl%buf_deps
117+
# buf_deps()
118+
119+
# rules_buf_dependencies()
120+
121+
# rules_buf_toolchains(version = "v1.12.0")
122+
123+
# gazelle_buf_dependencies()
124+
125+
#########################################
126+
## Bazel gPRC 规则集 初始化
127+
#########################################
128+
129+
# load("@rules_proto_grpc//:repositories.bzl", "rules_proto_grpc_repos", "rules_proto_grpc_toolchains")
130+
131+
# rules_proto_grpc_toolchains()
132+
133+
# rules_proto_grpc_repos()
134+
135+
#########################################
136+
## Bazel Protobuf 规则集 初始化
137+
#########################################
138+
139+
# load("@rules_proto//proto:repositories.bzl", "rules_proto_dependencies", "rules_proto_toolchains")
140+
141+
# rules_proto_dependencies()
142+
143+
# rules_proto_toolchains()

orm/ent/api/buf.lock

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# Generated by buf. DO NOT EDIT.
2+
version: v1
3+
deps:
4+
- remote: buf.build
5+
owner: envoyproxy
6+
repository: protoc-gen-validate
7+
commit: 6607b10f00ed4a3d98f906807131c44a
8+
- remote: buf.build
9+
owner: gogo
10+
repository: protobuf
11+
commit: 5461a3dfa9d941da82028ab185dc2a0e
12+
- remote: buf.build
13+
owner: googleapis
14+
repository: googleapis
15+
commit: 75b4300737fb4efca0831636be94e517
16+
- remote: buf.build
17+
owner: kratos
18+
repository: apis
19+
commit: c2de25f14fa445a79a054214f31d17a8
20+
- remote: buf.build
21+
owner: tx7do
22+
repository: gnostic
23+
commit: b9ecfa10359449f681e6e12b50b78f98

orm/ent/api/buf.yaml

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
version: v1
2+
build:
3+
excludes: [third_party]
4+
deps:
5+
- buf.build/googleapis/googleapis
6+
- buf.build/envoyproxy/protoc-gen-validate
7+
- buf.build/kratos/apis
8+
- buf.build/tx7do/gnostic
9+
- buf.build/gogo/protobuf
10+
breaking:
11+
use:
12+
- FILE
13+
lint:
14+
use:
15+
- DEFAULT
+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
syntax = "proto3";
2+
3+
package common.conf;
4+
5+
option go_package = "kratos-ent-example/gen/api/go/common/conf;conf";
6+
7+
import "common/conf/tracer.proto";
8+
import "common/conf/data.proto";
9+
import "common/conf/server.proto";
10+
import "common/conf/client.proto";
11+
import "common/conf/logger.proto";
12+
import "common/conf/registry.proto";
13+
import "common/conf/oss.proto";
14+
import "common/conf/config.proto";
15+
16+
// 引导信息
17+
message Bootstrap {
18+
Server server = 1;
19+
Client client = 2;
20+
Data data = 3;
21+
Tracer trace = 4;
22+
Logger logger = 5;
23+
Registry registry = 6;
24+
RemoteConfig config = 7;
25+
OSS oss = 8;
26+
}

orm/ent/api/common/conf/client.proto

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
syntax = "proto3";
2+
3+
package common.conf;
4+
5+
option go_package = "kratos-ent-example/gen/api/go/common/conf;conf";
6+
7+
import "google/protobuf/duration.proto";
8+
import "common/conf/middleware.proto";
9+
10+
// 客户端
11+
message Client {
12+
// REST
13+
message REST {
14+
google.protobuf.Duration timeout = 1; // 超时时间
15+
Middleware middleware = 2;
16+
}
17+
18+
// gPRC
19+
message GRPC {
20+
google.protobuf.Duration timeout = 1; // 超时时间
21+
Middleware middleware = 2;
22+
}
23+
24+
REST rest = 1; // REST服务
25+
GRPC grpc = 2; // gRPC服务
26+
}

0 commit comments

Comments
 (0)