From 1b6908e5f2de6fbe2b187844195c7922f69a123a Mon Sep 17 00:00:00 2001 From: mingqing Date: Thu, 16 Jan 2025 09:41:48 +0800 Subject: [PATCH 01/11] chore: develop 0.3.9-beta.1 --- VERSION | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/VERSION b/VERSION index 6678432..03fca44 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -0.3.8 +0.3.9-beta.1 From 2855938a6a7e33c49ca9dbf1521aa53237a95b9c Mon Sep 17 00:00:00 2001 From: mingqing Date: Mon, 10 Feb 2025 15:08:16 +0800 Subject: [PATCH 02/11] =?UTF-8?q?refactor:=20=E6=9B=B4=E6=96=B0=E7=A4=BA?= =?UTF-8?q?=E4=BE=8B=20demo.py=20=E4=BD=9C=E4=B8=BA=E7=BB=9F=E4=B8=80=20py?= =?UTF-8?q?thon=20=E8=A7=84=E8=8C=83=E8=84=9A=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- template/service/modeler/flow/script/demo.py | 50 +++++++++++++++++++- 1 file changed, 49 insertions(+), 1 deletion(-) diff --git a/template/service/modeler/flow/script/demo.py b/template/service/modeler/flow/script/demo.py index e75154b..d108225 100644 --- a/template/service/modeler/flow/script/demo.py +++ b/template/service/modeler/flow/script/demo.py @@ -1 +1,49 @@ -print("hello world") \ No newline at end of file +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- + +""" +脚本名称: demo.py +功能描述: 简要描述脚本功能 +作者: Your Name +日期: YYYY-MM-DD +版本: 1.0 +""" + +import sys +import logging +from typing import List + +# 配置日志 +logging.basicConfig( + level=logging.INFO, + format="%(asctime)s - %(levelname)s - %(message)s", + handlers=[logging.StreamHandler(sys.stdout)], + datefmt="%Y-%m-%d %H:%M:%S" +) + +def setup() -> None: + """初始化环境设置""" + logging.info("初始化环境") + +def process_data(data: List[int]) -> List[int]: + """ + 处理数据的示例函数 + + :param data: 输入的整数列表 + :return: 处理后的整数列表 + """ + return [x * 2 for x in data] + +def main() -> None: + """主函数""" + setup() + data = [1, 2, 3, 4, 5] + result = process_data(data) + logging.info(f"处理结果: {result}") + +if __name__ == "__main__": + try: + main() + except Exception as e: + logging.warning("出现异常") + sys.exit(1) From f3e4ca1b69911ca693782f86cdd29f4c39b9bccc Mon Sep 17 00:00:00 2001 From: mingqing Date: Tue, 11 Feb 2025 11:37:55 +0800 Subject: [PATCH 03/11] =?UTF-8?q?refactor:=20demo.py=20=E5=BC=82=E5=B8=B8?= =?UTF-8?q?=E5=A4=84=E7=90=86=E5=A0=86=E6=A0=88=E8=BE=93=E5=87=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- template/service/modeler/flow/script/demo.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/template/service/modeler/flow/script/demo.py b/template/service/modeler/flow/script/demo.py index d108225..01c1aa8 100644 --- a/template/service/modeler/flow/script/demo.py +++ b/template/service/modeler/flow/script/demo.py @@ -11,6 +11,7 @@ import sys import logging +import traceback from typing import List # 配置日志 @@ -45,5 +46,6 @@ def main() -> None: try: main() except Exception as e: - logging.warning("出现异常") + logging.error("出现异常: %s", e) + logging.error("堆栈信息:\n%s", traceback.format_exc()) sys.exit(1) From 01e3df9548649f620e1d71ba8633fa0c7b553606 Mon Sep 17 00:00:00 2001 From: mingqing Date: Wed, 7 May 2025 10:10:37 +0800 Subject: [PATCH 04/11] =?UTF-8?q?chore:=20=E6=9B=B4=E6=96=B0=20demo.py=20?= =?UTF-8?q?=E7=A4=BA=E4=BE=8B=E6=A8=A1=E7=89=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- template/service/modeler/flow/script/demo.py | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/template/service/modeler/flow/script/demo.py b/template/service/modeler/flow/script/demo.py index 01c1aa8..6e690c4 100644 --- a/template/service/modeler/flow/script/demo.py +++ b/template/service/modeler/flow/script/demo.py @@ -11,20 +11,24 @@ import sys import logging -import traceback +from datetime import datetime, timezone from typing import List # 配置日志 logging.basicConfig( level=logging.INFO, format="%(asctime)s - %(levelname)s - %(message)s", - handlers=[logging.StreamHandler(sys.stdout)], - datefmt="%Y-%m-%d %H:%M:%S" + datefmt="%Y-%m-%d %H:%M:%S", + stream=sys.stdout ) +# 全局变量 +update_time = datetime.now(timezone.utc).replace(microsecond=0).isoformat().replace("+00:00", "Z") + def setup() -> None: """初始化环境设置""" logging.info("初始化环境") + logging.info("更新时间: %s", update_time) def process_data(data: List[int]) -> List[int]: """ @@ -33,19 +37,22 @@ def process_data(data: List[int]) -> List[int]: :param data: 输入的整数列表 :return: 处理后的整数列表 """ + return [x * 2 for x in data] def main() -> None: """主函数""" setup() + + # 局部变量 data = [1, 2, 3, 4, 5] result = process_data(data) - logging.info(f"处理结果: {result}") + + logging.info("处理结果: %s", result) if __name__ == "__main__": try: main() except Exception as e: - logging.error("出现异常: %s", e) - logging.error("堆栈信息:\n%s", traceback.format_exc()) + logging.exception("出现异常") sys.exit(1) From 28abec2ca1e679979452559705d592050848891d Mon Sep 17 00:00:00 2001 From: mingqing Date: Tue, 26 Aug 2025 23:43:39 +0800 Subject: [PATCH 05/11] =?UTF-8?q?refactor:=20=E5=88=86=E7=A6=BB=20independ?= =?UTF-8?q?ent=5Fcfg=20=E5=B1=9E=E6=80=A7=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/modeler/independent_cfg.go.tmpl | 34 -------------- .../modeler/independent_option.go.tmpl | 44 +++++++++++++++++++ 2 files changed, 44 insertions(+), 34 deletions(-) create mode 100644 template/service/modeler/independent_option.go.tmpl diff --git a/template/service/modeler/independent_cfg.go.tmpl b/template/service/modeler/independent_cfg.go.tmpl index 871eb66..7e7c90f 100644 --- a/template/service/modeler/independent_cfg.go.tmpl +++ b/template/service/modeler/independent_cfg.go.tmpl @@ -4,8 +4,6 @@ import ( "context" "fmt" - entsql "entgo.io/ent/dialect/sql" - "github.com/grpc-kit/pkg/cfg" "github.com/sirupsen/logrus" "{{ .Global.Repository }}/modeler/ent" @@ -21,38 +19,6 @@ type IndependentCfg struct { Name string `mapstructure:"name"` } -// ClientIndependentOption 用户自定义初始化资源选项 -type ClientIndependentOption func(cfg *IndependentCfg) - -// WithLogger 传递日志实例 -func WithLogger(logger *logrus.Entry) ClientIndependentOption { - return func(cfg *IndependentCfg) { - cfg.logger = logger - } -} - -// WithDatabaseEntDriver 传递 ent 数据库实例 -func WithDatabaseEntDriver(driver *entsql.Driver) ClientIndependentOption { - return func(cfg *IndependentCfg) { - client := ent.NewClient(ent.Driver(driver)) - cfg.db = client - } -} - -// WithWorkflow 传递流水线配置 -func WithWorkflow(logger *logrus.Entry, fcc *cfg.FlowClientConfig) ClientIndependentOption { - return func(cfg *IndependentCfg) { - if fcc != nil { - client, err := flow.NewClient(logger, fcc) - if err != nil { - panic(err) - } - - cfg.flow = client - } - } -} - // Init 用于初始化实例 func (i *IndependentCfg) Init(opts ...ClientIndependentOption) error { ctx := context.Background() diff --git a/template/service/modeler/independent_option.go.tmpl b/template/service/modeler/independent_option.go.tmpl new file mode 100644 index 0000000..e195271 --- /dev/null +++ b/template/service/modeler/independent_option.go.tmpl @@ -0,0 +1,44 @@ +// Code generated by "grpc-kit-cli/{{ .Global.ReleaseVersion }}". DO NOT EDIT. + +package modeler + +import ( + entsql "entgo.io/ent/dialect/sql" + "github.com/grpc-kit/pkg/cfg" + "github.com/sirupsen/logrus" + + "{{ .Global.Repository }}/modeler/ent" + "{{ .Global.Repository }}/modeler/flow" +) + +// ClientIndependentOption 用户自定义初始化资源选项 +type ClientIndependentOption func(cfg *IndependentCfg) + +// WithLogger 传递日志实例 +func WithLogger(logger *logrus.Entry) ClientIndependentOption { + return func(cfg *IndependentCfg) { + cfg.logger = logger + } +} + +// WithDatabaseEntDriver 传递 ent 数据库实例 +func WithDatabaseEntDriver(driver *entsql.Driver) ClientIndependentOption { + return func(cfg *IndependentCfg) { + client := ent.NewClient(ent.Driver(driver)) + cfg.db = client + } +} + +// WithWorkflow 传递流水线配置 +func WithWorkflow(logger *logrus.Entry, fcc *cfg.FlowClientConfig) ClientIndependentOption { + return func(cfg *IndependentCfg) { + if fcc != nil { + client, err := flow.NewClient(logger, fcc) + if err != nil { + panic(err) + } + + cfg.flow = client + } + } +} From 7b76b86952c0a606ebc9fa92d69f97c804030e0f Mon Sep 17 00:00:00 2001 From: mingqing Date: Tue, 26 Aug 2025 23:44:20 +0800 Subject: [PATCH 06/11] =?UTF-8?q?build:=20=E6=9C=80=E4=BD=8E=E4=BE=9D?= =?UTF-8?q?=E8=B5=96=20go=201.24=20=E7=89=88=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- template/service/go.mod.tmpl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/template/service/go.mod.tmpl b/template/service/go.mod.tmpl index bfc49fb..ee24121 100644 --- a/template/service/go.mod.tmpl +++ b/template/service/go.mod.tmpl @@ -1,6 +1,6 @@ module {{ .Global.Repository }} -go 1.22.7 +go 1.24 require ( github.com/grpc-ecosystem/grpc-gateway/v2 v2.24.0 From ac5bbb4b726853d73f928d9a9e88d88a813a901a Mon Sep 17 00:00:00 2001 From: mingqing Date: Fri, 10 Oct 2025 15:13:04 +0800 Subject: [PATCH 07/11] =?UTF-8?q?docs(template):=20=E6=B7=BB=E5=8A=A0=20rp?= =?UTF-8?q?c=20=E6=96=B9=E6=B3=95=E5=AE=9A=E4=B9=89=E7=9A=84=E6=B3=A8?= =?UTF-8?q?=E8=A7=A3=E7=A4=BA=E4=BE=8B=E5=8F=82=E8=80=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 添加书籍管理参考示例注释,展示标准CRUD操作配置方式 -保留Demo示例作为默认实现参考- 所有新增内容遵循模板变量引用规范,支持动态渲染 --- .../service/v1/microservice.gateway.yaml.tmpl | 26 +++++++++++++++++++ .../service/v1/microservice.proto.tmpl | 14 ++++++++++ 2 files changed, 40 insertions(+) diff --git a/template/service/api/template/service/v1/microservice.gateway.yaml.tmpl b/template/service/api/template/service/v1/microservice.gateway.yaml.tmpl index d4c842f..8e13165 100644 --- a/template/service/api/template/service/v1/microservice.gateway.yaml.tmpl +++ b/template/service/api/template/service/v1/microservice.gateway.yaml.tmpl @@ -3,9 +3,35 @@ config_version: 3 http: rules: + # 内置服务 + ## 健康检查 - selector: {{ .Global.ProtoPackage }}.{{ .Global.ServiceTitle }}.HealthCheck get: "/api/healthz" + # 参考示例,书籍管理,实现相同一组任务的方法整合在一起,前后均需空行隔开 + ## 获取书籍详情 + #- selector: {{ .Global.ProtoPackage }}.{{ .Global.ServiceTitle }}.GetBook + # get: "/api/publishers/{publisher_id}/books/{book_id}" + ## 获取书籍列表 + #- selector: {{ .Global.ProtoPackage }}.{{ .Global.ServiceTitle }}.ListBooks + # get: "/api/publishers/{publisher_id}/books" + ## 创建书籍实体 + #- selector: {{ .Global.ProtoPackage }}.{{ .Global.ServiceTitle }}.CreateBook + # post: "/api/publishers/{publisher_id}/books" + # body: "book" + ## 更新书籍实体 + #- selector: {{ .Global.ProtoPackage }}.{{ .Global.ServiceTitle }}.UpdateBook + # patch: "/api/publishers/{publisher_id}/books/{book_id}" + # body: "book" + ## 删除书籍实体 + #- selector: {{ .Global.ProtoPackage }}.{{ .Global.ServiceTitle }}.DeleteBook + # delete: "/api/publishers/{publisher_id}/books/{book_id}" + ## 归档书籍实体 + #- selector: {{ .Global.ProtoPackage }}.{{ .Global.ServiceTitle }}.ArchiveBook + # post: "/api/publishers/{publisher_id}/books/{book_id}:archive" + # body: "*" + + # 示例实现 - selector: {{ .Global.ProtoPackage }}.{{ .Global.ServiceTitle }}.Demo post: "/api/demo" body: "*" diff --git a/template/service/api/template/service/v1/microservice.proto.tmpl b/template/service/api/template/service/v1/microservice.proto.tmpl index be8b49d..ef40409 100644 --- a/template/service/api/template/service/v1/microservice.proto.tmpl +++ b/template/service/api/template/service/v1/microservice.proto.tmpl @@ -12,6 +12,20 @@ import "github.com/grpc-kit/api/known/status/v1/response.proto"; // 该微服务支持的 RPC 方法定义 service {{ title .Global.ServiceTitle }} { + // 内置服务,健康检查 rpc HealthCheck(grpc_kit.api.known.status.v1.HealthCheckRequest) returns (grpc_kit.api.known.status.v1.HealthCheckResponse) {} + + // 参考示例,书籍管理,实现相同一组任务的方法整合在一起,前后均需空行隔开 + // rpc GetBook(GetBookRequest) returns (Book) {} + // rpc ListBooks(ListBooksRequest) returns (ListBooksResponse) {} + // rpc CreateBook(CreateBookRequest) returns (Book) {} + // rpc UpdateBook(CreateBookRequest) returns (Book) {} + // rpc DeleteBook(DeleteBookRequest) returns (google.protobuf.Empty) {} + // rpc ArchiveBook(ArchiveBookRequest) returns (ArchiveBookResponse) {} + + // 示例实现,可以删除 rpc Demo(DemoRequest) returns (DemoResponse) {} + + // xx 管理,实现相同一组任务的方法整合在一起 + // ... } From ae748aef2f1330cd4c8182126307ad8528b4edd6 Mon Sep 17 00:00:00 2001 From: mingqing Date: Fri, 10 Oct 2025 15:43:29 +0800 Subject: [PATCH 08/11] =?UTF-8?q?feat(proto):=20=E6=9B=B4=E6=96=B0proto?= =?UTF-8?q?=E6=A8=A1=E6=9D=BF=E4=B8=AD=E7=9A=84=E5=86=85=E9=83=A8=E5=BC=95?= =?UTF-8?q?=E7=94=A8=E8=B7=AF=E5=BE=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 在demo.proto.tmpl中添加对同服务内microservice.common.proto的相对路径引用 - 移除DemoResponse中嵌套的Pong消息定义 - 调整microservice.proto.tmpl中的导入注释及顺序 - 修改rpc_demo.go.tmpl中Pong结构体的引用方式 --- .../service/api/template/service/v1/demo.proto.tmpl | 12 +++--------- .../api/template/service/v1/microservice.proto.tmpl | 1 + template/service/handler/rpc_demo.go.tmpl | 2 +- 3 files changed, 5 insertions(+), 10 deletions(-) diff --git a/template/service/api/template/service/v1/demo.proto.tmpl b/template/service/api/template/service/v1/demo.proto.tmpl index 7c42f14..2288f0e 100644 --- a/template/service/api/template/service/v1/demo.proto.tmpl +++ b/template/service/api/template/service/v1/demo.proto.tmpl @@ -11,6 +11,9 @@ import "google/protobuf/empty.proto"; // 引入第三方依赖的 proto 文件 import "github.com/grpc-kit/api/known/example/v1/example.proto"; +// 同服务内的 proto 文件使用相对路径引用,既不包含代码仓库前缀 +import "api/{{ .Global.ProductCode }}/{{ .Global.ShortName }}/{{ .Template.Service.APIVersion }}/microservice.common.proto"; + // DemoRequest Demo 方法请求可使用的接口参数 message DemoRequest { // UUID 资源编号 @@ -22,15 +25,6 @@ message DemoRequest { // DemoResponse Demo方法响应的具体内容 message DemoResponse { - - message Pong { - // UUID 资源编号 - string uuid = 1; - - // Pong 单个资源响应内容 - grpc_kit.api.known.example.v1.ExampleResponse pong = 2; - } - // Pong 返回创建的资源 Pong pong = 1; diff --git a/template/service/api/template/service/v1/microservice.proto.tmpl b/template/service/api/template/service/v1/microservice.proto.tmpl index ef40409..c59a898 100644 --- a/template/service/api/template/service/v1/microservice.proto.tmpl +++ b/template/service/api/template/service/v1/microservice.proto.tmpl @@ -5,6 +5,7 @@ package {{ .Global.ProtoPackage }}; option go_package = "{{ .Global.Repository }}/api/{{ .Global.ProductCode }}/{{ .Global.ShortName }}/{{ .Template.Service.APIVersion }};{{ .Global.ShortName }}{{ .Template.Service.APIVersion }}"; // 同服务内的 proto 文件使用相对路径引用,既不包含代码仓库前缀 +//import "api/{{ .Global.ProductCode }}/{{ .Global.ShortName }}/{{ .Template.Service.APIVersion }}/microservice.common.proto"; import "api/{{ .Global.ProductCode }}/{{ .Global.ShortName }}/{{ .Template.Service.APIVersion }}/demo.proto"; // 引入依赖的外部 proto 文件 diff --git a/template/service/handler/rpc_demo.go.tmpl b/template/service/handler/rpc_demo.go.tmpl index a148cc0..97ff1d4 100644 --- a/template/service/handler/rpc_demo.go.tmpl +++ b/template/service/handler/rpc_demo.go.tmpl @@ -25,7 +25,7 @@ func (m *Microservice) Demo(ctx context.Context, req *pb.DemoRequest) (*pb.DemoR Ping: &examplev1.ExampleResponse{}, // POST /api/demo // GET /api/demo/{uuid} - Pong: &pb.DemoResponse_Pong{ + Pong: &pb.Pong{ Uuid: "99feafb5-bed6-4daf-927a-69a2ab80c485", Pong: &examplev1.ExampleResponse{}, }, From 0cd4482d29665d64d0a920df4c5f08552bec1c43 Mon Sep 17 00:00:00 2001 From: mingqing Date: Fri, 10 Oct 2025 15:43:51 +0800 Subject: [PATCH 09/11] =?UTF-8?q?feat(proto):=20=E6=B7=BB=E5=8A=A0?= =?UTF-8?q?=E5=BE=AE=E6=9C=8D=E5=8A=A1=E9=80=9A=E7=94=A8=20proto=20?= =?UTF-8?q?=E6=A8=A1=E6=9D=BF=E6=96=87=E4=BB=B6-=20=E5=88=9B=E5=BB=BA?= =?UTF-8?q?=E4=BA=86=E6=96=B0=E7=9A=84=20proto=20=E6=A8=A1=E6=9D=BF?= =?UTF-8?q?=E6=96=87=E4=BB=B6=EF=BC=8C=E7=94=A8=E4=BA=8E=E5=AE=9A=E4=B9=89?= =?UTF-8?q?=E5=BE=AE=E6=9C=8D=E5=8A=A1=E7=9A=84=E9=80=9A=E7=94=A8=E6=B6=88?= =?UTF-8?q?=E6=81=AF=E7=BB=93=E6=9E=84-=20=E5=AE=9A=E4=B9=89=E4=BA=86=20Po?= =?UTF-8?q?ng=20=E6=B6=88=E6=81=AF=E7=B1=BB=E5=9E=8B=EF=BC=8C=E5=8C=85?= =?UTF-8?q?=E5=90=AB=20uuid=E3=80=81pong=20=E5=93=8D=E5=BA=94=E5=86=85?= =?UTF-8?q?=E5=AE=B9=E4=BB=A5=E5=8F=8A=E6=97=B6=E6=88=B3=E5=AD=97=E6=AE=B5?= =?UTF-8?q?=20-=20=E5=BC=95=E5=85=A5=E4=BA=86=20google.protobuf.timestamp.?= =?UTF-8?q?proto=20=E5=92=8C=E7=AC=AC=E4=B8=89=E6=96=B9=20example.proto?= =?UTF-8?q?=E4=BE=9D=E8=B5=96=20-=20=E9=85=8D=E7=BD=AE=E4=BA=86=20go=5Fpac?= =?UTF-8?q?kage=20=E9=80=89=E9=A1=B9=EF=BC=8C=E6=8C=87=E5=AE=9A=E7=94=9F?= =?UTF-8?q?=E6=88=90=E7=9A=84=20Go=E4=BB=A3=E7=A0=81=E5=8C=85=E8=B7=AF?= =?UTF-8?q?=E5=BE=84=E5=92=8C=E5=90=8D=E7=A7=B0=20-=20=E8=AE=BE=E7=BD=AE?= =?UTF-8?q?=E4=BA=86=20package=20=E5=90=8D=E7=A7=B0=E5=8D=A0=E4=BD=8D?= =?UTF-8?q?=E7=AC=A6=EF=BC=8C=E6=94=AF=E6=8C=81=E6=A0=B9=E6=8D=AE=E5=85=B7?= =?UTF-8?q?=E4=BD=93=E5=BE=AE=E6=9C=8D=E5=8A=A1=E5=90=8D=E7=A7=B0=E8=BF=9B?= =?UTF-8?q?=E8=A1=8C=E6=9B=BF=E6=8D=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/v1/microservice.common.proto.tmpl | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 template/service/api/template/service/v1/microservice.common.proto.tmpl diff --git a/template/service/api/template/service/v1/microservice.common.proto.tmpl b/template/service/api/template/service/v1/microservice.common.proto.tmpl new file mode 100644 index 0000000..244916f --- /dev/null +++ b/template/service/api/template/service/v1/microservice.common.proto.tmpl @@ -0,0 +1,23 @@ +syntax = "proto3"; + +// 根据具体的微服务名称做更改 +package {{ .Global.ProtoPackage }}; + +option go_package = "{{ .Global.Repository }}/api/{{ .Global.ProductCode }}/{{ .Global.ShortName }}/{{ .Template.Service.APIVersion }};{{ .Global.ShortName }}{{ .Template.Service.APIVersion }}"; + +// 引入 google 公共类型 +import "google/protobuf/timestamp.proto"; + +// 引入第三方依赖的 proto 文件 +import "github.com/grpc-kit/api/known/example/v1/example.proto"; + +message Pong { + // UUID 资源编号 + string uuid = 1; + + // Pong 单个资源响应内容 + grpc_kit.api.known.example.v1.ExampleResponse pong = 2; + + google.protobuf.Timestamp created_at = 8; + google.protobuf.Timestamp updated_at = 9; +} \ No newline at end of file From f18cc5ec88c37c76935f99455a2f056e9bd4d870 Mon Sep 17 00:00:00 2001 From: mingqing Date: Wed, 14 Jan 2026 11:55:19 +0800 Subject: [PATCH 10/11] =?UTF-8?q?refactor(flow):=20=E8=B0=83=E6=95=B4?= =?UTF-8?q?=E5=B7=A5=E4=BD=9C=E6=B5=81=E7=9B=AE=E5=BD=95=E7=BB=93=E6=9E=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- template/service/modeler/flow/README.md | 27 ++++++++++++++ template/service/modeler/flow/flow.go.tmpl | 36 ++++++++++++++++++- .../service/modeler/flow/script/embed.go.tmpl | 4 +-- .../modeler/flow/script/{ => example}/demo.py | 4 +++ .../modeler/flow/script/{ => example}/demo.sh | 0 .../modeler/flow/template/demo.go.tmpl | 1 - .../flow/template/example/demo.go.tmpl | 1 + 7 files changed, 69 insertions(+), 4 deletions(-) create mode 100644 template/service/modeler/flow/README.md rename template/service/modeler/flow/script/{ => example}/demo.py (93%) rename template/service/modeler/flow/script/{ => example}/demo.sh (100%) delete mode 100644 template/service/modeler/flow/template/demo.go.tmpl create mode 100644 template/service/modeler/flow/template/example/demo.go.tmpl diff --git a/template/service/modeler/flow/README.md b/template/service/modeler/flow/README.md new file mode 100644 index 0000000..781d8f4 --- /dev/null +++ b/template/service/modeler/flow/README.md @@ -0,0 +1,27 @@ +## 工作流 + +规范: + +```text +# 用于定义 argo workflow 流程编排 +template/ + +# 用于实现工作流脚本编码 +script/ +``` + +每个工作流根据类型分组在各自文件夹下,如: + +```text +template/example/ +script/example/ +``` + +当创建新目录时,需要在 `embed.go` 中添加对应目录的文件引用,如: + +```text +//go:embed example/*.sh +//go:embed example/*.py +``` + +所有脚本大小尽量避免超过 100kb 否则有可能无法运行成功。 diff --git a/template/service/modeler/flow/flow.go.tmpl b/template/service/modeler/flow/flow.go.tmpl index 7062aad..335db24 100644 --- a/template/service/modeler/flow/flow.go.tmpl +++ b/template/service/modeler/flow/flow.go.tmpl @@ -32,4 +32,38 @@ func NewClient(logger *logrus.Entry, fcc *cfg.FlowClientConfig) (*Client, error) // Create xx func (w *Client) Create(ctx context.Context) error { return nil -} \ No newline at end of file +} + +/* +func (w *Client) sync(ctx context.Context, templates ...*wfv1.WorkflowTemplate) error { + for _, tmpl := range templates { + un := &unstructured.Unstructured{} + + rawBody, err := json.Marshal(tmpl) + if err != nil { + return err + } + + if err = un.UnmarshalJSON(rawBody); err != nil { + return err + } + + gvk := un.GroupVersionKind() + res := schema.GroupVersionResource{ + Group: gvk.Group, + Version: gvk.Version, + Resource: fmt.Sprintf("%v%v", strings.ToLower(gvk.Kind), "s"), + } + + _, err = w.dynamicset. + Resource(res). + Namespace(un.GetNamespace()). + Apply(ctx, un.GetName(), un, metav1.ApplyOptions{Force: true, FieldManager: w.config.Appname}) + if err != nil { + return err + } + } + + return nil +} +*/ \ No newline at end of file diff --git a/template/service/modeler/flow/script/embed.go.tmpl b/template/service/modeler/flow/script/embed.go.tmpl index 19731e6..e0d99dc 100644 --- a/template/service/modeler/flow/script/embed.go.tmpl +++ b/template/service/modeler/flow/script/embed.go.tmpl @@ -4,6 +4,6 @@ import ( "embed" ) -//go:embed *.sh -//go:embed *.py +//go:embed example/*.sh +//go:embed example/*.py var Assets embed.FS \ No newline at end of file diff --git a/template/service/modeler/flow/script/demo.py b/template/service/modeler/flow/script/example/demo.py similarity index 93% rename from template/service/modeler/flow/script/demo.py rename to template/service/modeler/flow/script/example/demo.py index 6e690c4..81726d5 100644 --- a/template/service/modeler/flow/script/demo.py +++ b/template/service/modeler/flow/script/example/demo.py @@ -51,6 +51,10 @@ def main() -> None: logging.info("处理结果: %s", result) if __name__ == "__main__": + # 全局变量定义,使用大写 + API_ENDPOINT = "" + API_TOKEN = "" + try: main() except Exception as e: diff --git a/template/service/modeler/flow/script/demo.sh b/template/service/modeler/flow/script/example/demo.sh similarity index 100% rename from template/service/modeler/flow/script/demo.sh rename to template/service/modeler/flow/script/example/demo.sh diff --git a/template/service/modeler/flow/template/demo.go.tmpl b/template/service/modeler/flow/template/demo.go.tmpl deleted file mode 100644 index 38cdfe4..0000000 --- a/template/service/modeler/flow/template/demo.go.tmpl +++ /dev/null @@ -1 +0,0 @@ -package template diff --git a/template/service/modeler/flow/template/example/demo.go.tmpl b/template/service/modeler/flow/template/example/demo.go.tmpl new file mode 100644 index 0000000..f7ec372 --- /dev/null +++ b/template/service/modeler/flow/template/example/demo.go.tmpl @@ -0,0 +1 @@ +package example From aab727d986cd4027eae9283b374ea52cdf33d7cc Mon Sep 17 00:00:00 2001 From: mingqing Date: Fri, 16 Jan 2026 15:29:53 +0800 Subject: [PATCH 11/11] =?UTF-8?q?refactor(flow):=20=E5=AE=8C=E5=96=84?= =?UTF-8?q?=E7=A4=BA=E4=BE=8B=E6=B5=81=E6=B0=B4=E7=BA=BF=E7=BC=96=E6=8E=92?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- template/service/modeler/flow/flow.go.tmpl | 11 ++- .../flow/template/example/demo.go.tmpl | 1 - .../flow/template/example/python.go.tmpl | 97 +++++++++++++++++++ .../flow/template/example/shell.go.tmpl | 97 +++++++++++++++++++ 4 files changed, 204 insertions(+), 2 deletions(-) delete mode 100644 template/service/modeler/flow/template/example/demo.go.tmpl create mode 100644 template/service/modeler/flow/template/example/python.go.tmpl create mode 100644 template/service/modeler/flow/template/example/shell.go.tmpl diff --git a/template/service/modeler/flow/flow.go.tmpl b/template/service/modeler/flow/flow.go.tmpl index 335db24..c72172f 100644 --- a/template/service/modeler/flow/flow.go.tmpl +++ b/template/service/modeler/flow/flow.go.tmpl @@ -31,6 +31,15 @@ func NewClient(logger *logrus.Entry, fcc *cfg.FlowClientConfig) (*Client, error) // Create xx func (w *Client) Create(ctx context.Context) error { + /* + if err := w.sync(ctx, + example.NewExampleShell(w.config).Template(), + example.NewExamplePython(w.config).Template(), + ); err != nil { + return err + } + */ + return nil } @@ -66,4 +75,4 @@ func (w *Client) sync(ctx context.Context, templates ...*wfv1.WorkflowTemplate) return nil } -*/ \ No newline at end of file +*/ diff --git a/template/service/modeler/flow/template/example/demo.go.tmpl b/template/service/modeler/flow/template/example/demo.go.tmpl deleted file mode 100644 index f7ec372..0000000 --- a/template/service/modeler/flow/template/example/demo.go.tmpl +++ /dev/null @@ -1 +0,0 @@ -package example diff --git a/template/service/modeler/flow/template/example/python.go.tmpl b/template/service/modeler/flow/template/example/python.go.tmpl new file mode 100644 index 0000000..8aab1e5 --- /dev/null +++ b/template/service/modeler/flow/template/example/python.go.tmpl @@ -0,0 +1,97 @@ +package example + +/* +import ( + "fmt" + + wfv1 "github.com/argoproj/argo-workflows/v3/pkg/apis/workflow/v1alpha1" + "github.com/grpc-kit/pkg/cfg" + corev1 "k8s.io/api/core/v1" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "k8s.io/utils/ptr" + + "{{ .Global.Repository }}/modeler/flow/script" +) + +// ExamplePython xx +type ExamplePython struct { + config *cfg.FlowClientConfig + template *wfv1.WorkflowTemplate +} + +// NewExampleShell xx +func NewExamplePython(config *cfg.FlowClientConfig) *ExamplePython { + t := &wfv1.WorkflowTemplate{ + TypeMeta: metav1.TypeMeta{ + Kind: "WorkflowTemplate", + APIVersion: "argoproj.io/v1alpha1", + }, + ObjectMeta: metav1.ObjectMeta{ + Name: fmt.Sprintf("%v-example-python", config.Appname), + Namespace: config.Namespace, + }, + Spec: wfv1.WorkflowSpec{ + Entrypoint: "main", + ServiceAccountName: "executor", + Volumes: []corev1.Volume{ + { + Name: "global-tmp", + VolumeSource: corev1.VolumeSource{ + EmptyDir: &corev1.EmptyDirVolumeSource{}, + }, + }, + }, + Templates: []wfv1.Template{}, + ActiveDeadlineSeconds: ptr.To[int64](3600), + ArchiveLogs: ptr.To[bool](false), + }, + } + + d := &ExamplePython{config: config, template: t} + d.initTemplates() + + return d +} + +// Template xx +func (d *ExamplePython) Template() *wfv1.WorkflowTemplate { + return d.template +} + +func (d *ExamplePython) initTemplates() { + d.template.Spec.Templates = append(d.template.Spec.Templates, d.mainTemplate()) + d.template.Spec.Templates = append(d.template.Spec.Templates, d.scriptDemo()) +} + +func (d *ExamplePython) mainTemplate() wfv1.Template { + return wfv1.Template{ + Name: "main", + DAG: &wfv1.DAGTemplate{ + Tasks: []wfv1.DAGTask{ + { + Name: "demo", + Template: "demo", + }, + }, + }, + } +} + +func (d *ExamplePython) scriptDemo() wfv1.Template { + sourceRaw, err := script.Assets.ReadFile("example/demo.py") + if err != nil { + panic(err) + } + + return wfv1.Template{ + Name: "demo", + Script: &wfv1.ScriptTemplate{ + Container: corev1.Container{ + Image: "ccr.ccs.tencentyun.com/opsaid/python:alpine3.6", + Command: []string{"python"}, + }, + Source: string(sourceRaw), + }, + } +} +*/ diff --git a/template/service/modeler/flow/template/example/shell.go.tmpl b/template/service/modeler/flow/template/example/shell.go.tmpl new file mode 100644 index 0000000..e91af4b --- /dev/null +++ b/template/service/modeler/flow/template/example/shell.go.tmpl @@ -0,0 +1,97 @@ +package example + +/* +import ( + "fmt" + + wfv1 "github.com/argoproj/argo-workflows/v3/pkg/apis/workflow/v1alpha1" + "github.com/grpc-kit/pkg/cfg" + corev1 "k8s.io/api/core/v1" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "k8s.io/utils/ptr" + + {{ .Global.Repository }}/modeler/flow/script +) + +// ExampleShell xx +type ExampleShell struct { + config *cfg.FlowClientConfig + template *wfv1.WorkflowTemplate +} + +// NewExampleShell xx +func NewExampleShell(config *cfg.FlowClientConfig) *ExampleShell { + t := &wfv1.WorkflowTemplate{ + TypeMeta: metav1.TypeMeta{ + Kind: "WorkflowTemplate", + APIVersion: "argoproj.io/v1alpha1", + }, + ObjectMeta: metav1.ObjectMeta{ + Name: fmt.Sprintf("%v-example-shell", config.Appname), + Namespace: config.Namespace, + }, + Spec: wfv1.WorkflowSpec{ + Entrypoint: "main", + ServiceAccountName: "executor", + Volumes: []corev1.Volume{ + { + Name: "global-tmp", + VolumeSource: corev1.VolumeSource{ + EmptyDir: &corev1.EmptyDirVolumeSource{}, + }, + }, + }, + Templates: []wfv1.Template{}, + ActiveDeadlineSeconds: ptr.To[int64](3600), + ArchiveLogs: ptr.To[bool](false), + }, + } + + d := &ExampleShell{config: config, template: t} + d.initTemplates() + + return d +} + +// Template xx +func (d *ExampleShell) Template() *wfv1.WorkflowTemplate { + return d.template +} + +func (d *ExampleShell) initTemplates() { + d.template.Spec.Templates = append(d.template.Spec.Templates, d.mainTemplate()) + d.template.Spec.Templates = append(d.template.Spec.Templates, d.scriptDemo()) +} + +func (d *ExampleShell) mainTemplate() wfv1.Template { + return wfv1.Template{ + Name: "main", + DAG: &wfv1.DAGTemplate{ + Tasks: []wfv1.DAGTask{ + { + Name: "demo", + Template: "demo", + }, + }, + }, + } +} + +func (d *ExampleShell) scriptDemo() wfv1.Template { + sourceRaw, err := script.Assets.ReadFile("example/demo.sh") + if err != nil { + panic(err) + } + + return wfv1.Template{ + Name: "demo", + Script: &wfv1.ScriptTemplate{ + Container: corev1.Container{ + Image: "ccr.ccs.tencentyun.com/opsaid/minideb:bullseye", + Command: []string{"sh"}, + }, + Source: string(sourceRaw), + }, + } +} +*/