开箱即用的GO后台管理系统 Kratos Admin - 代码生成工具集

本文涉及的产品
任务调度 XXL-JOB 版免费试用,400 元额度,开发版规格
注册配置 MSE Nacos/ZooKeeper,118元/月
服务治理 MSE Sentinel/OpenSergo,Agent数量 不受限
简介: Kratos Admin 是一款开箱即用的 Go 后台管理系统,配套代码生成工具集(cfgexp、sql2orm、sql2proto、sql2kratos),支持配置导出、数据库转 ORM、Protobuf 及 Kratos 微服务代码生成,助力高效开发。

开箱即用的GO后台管理系统 Kratos Admin - 代码生成工具集

我们为go-kratos-admin这个项目打造了一个代码生成工具集。

  • cfgexp 用于将服务本地配置导入到远程配置系统,支持:Etd、Consul、Nacos……
  • sql2orm 用于把数据库的表结构导入,并且生成为ORM代码,支持:ENT、GORM……
  • sql2proto 用于把数据的表结构导入,并且生成gRPC、REST的Protobuf代码。
  • sql2kratos 用于把数据的表结构导入,并且生成一整套的Kratos服务代码。

项目代码地址:

cfgexp

该工具将本地配置文件导出到Consul或Etcd等远程配置系统,从而更轻松地管理分布式系统中的配置。

现在已经支持的远程配置系统有:

  • Etcd
  • Consul
  • Nacos

如何安装

go install github.com/tx7do/kratos-cli/config-exporter/cmd/cfgexp@latest

如何使用

Config Exporter is a tool to export configuration from remote services like Consul or Etcd to local files.

Usage:
  cfgexp [flags]

Flags:
  -a, --addr string    remote config service address (default "127.0.0.1:8500")
  -e, --env string     environment name, like dev, test, prod, etc. (default "dev")
  -g, --group string   group name, this name is used to key prefix in remote config service (default "DEFAULT_GROUP")
  -h, --help           help for cfgexp
  -n, --ns string      namespace ID, used for Nacos (default "public")
  -p, --proj string    project name, this name is used to key prefix in remote config service
  -r, --root string    project root dir (default "./")
  -t, --type string    remote config service name (consul, etcd, etc.) (default "consul")

示例

Etcd

cfgexp \
    -t "etcd" \
    -a "localhost:2379" \
    -p "kratos_admin"

consul

cfgexp \
    -t "consul" \
    -a "localhost:8500" \
    -p "kratos_admin"

Nacos

cfgexp \
    -t "nacos" \
    -a "localhost:8848" \
    -p "kratos_admin" \
    -n "public" \
    -e "dev" \
    -g "DEFAULT_GROUP"

sql2orm

该工具导入 SQL 数据库的表结构,并生成用于 Kratos 微服务的 ORM代码。

支持的ORM:

  • ent
  • GORM

如何安装

go install github.com/tx7do/kratos-cli/sql-orm/cmd/sql2orm@latest

如何使用

sql2orm is a tool to generate ORM code from SQL database schemas.

Usage:
  sql2orm [flags]

Flags:
  -d, --dao-path string          output path for DAO code (for gorm) (default "./daos/")
  -v, --drv string               Database driver name to use (mysql, postgres, sqlite...) (default "mysql")
  -n, --dsn string               Data source name (connection information), for example:
                                 "mysql://user:pass@tcp(localhost:3306)/dbname"
                                 "postgres://user:pass@host:port/dbname"
  -e, --exclude-tables strings   comma-separated list of tables to exclude
  -h, --help                     help for sql2orm
  -o, --orm string               ORM type to use (ent, gorm) (default "ent")
  -s, --schema-path string       output path for schema (default "./ent/schema/")
  -t, --tables strings           comma-separated list of tables to inspect (all if empty)

示例

Ent

sql2orm \
  --orm "ent" \
  --dsn "postgres://postgres:pass@localhost:5432/test?sslmode=disable" \
  --schema-path "./ent/schema"

GORM

sql2orm \
  --orm "gorm" \
  --drv "postgres" \
  --dsn "postgres://postgres:pass@localhost:5432/test?sslmode=disable" \
  --schema-path "./daos/models" \
  --dao-path "./daos/"

sql2proto

该工具导入 SQL 数据库的表结构,并生成用于 Kratos 微服务的 Protobuf 代码。

如何安装

go install github.com/tx7do/kratos-cli/sql-proto/cmd/sql2proto@latest

如何使用

sql2proto is a tool to import SQL database schema and generate Protobuf code.

Usage:
  sql2proto [flags]

Flags:
  -n, --dsn string          Data source name (connection information), for example:
                            "mysql://user:pass@tcp(localhost:3306)/dbname"
                            "postgres://user:pass@host:port/dbname"
  -e, --excludes strings    comma-separated list of tables to exclude
  -h, --help                help for sql2proto
  -i, --includes strings    comma-separated list of tables to inspect (all if empty)
  -m, --module string       module name for the generated code, e.g., 'admin' (default "admin")
  -o, --output string       output path for protobuf schema files (default "./api/protos/")
  -s, --src-module string   Source module name, for REST service generate, e.g., "admin" (default "user")
  -t, --type string         generate RPC service type, "rest" for REST service, "grpc" for gRPC service (default "grpc")
  -v, --version string      Version of the module, e.g., 'v1' (default "v1")

示例

生成gRPC服务的Proto:

sql2proto \
  -n "postgres://postgres:pass@localhost:5432/test?sslmode=disable" \
  -o "./api/protos" \
  -t "grpc" \
  -m "user"

生成REST服务的Proto:

sql2proto \
  -n "mysql://root:pass@localhost:3306/test" \
  -o "./api/protos" \
  -t "rest" \
  -m "admin" \
  -s "user"

sql2kratos

该工具导入 SQL 数据库的表结构,并生成 Kratos 微服务代码。

如何安装

go install github.com/tx7do/kratos-cli/sql-kratos/cmd/sql2kratos@latest

如何使用

sql2kratos imports the SQL database schemas and generates Kratos microservice code.

Usage:
  sql2kratos [flags]

Flags:
  -n, --dsn string          Data source name (connection information), for example:
                            "mysql://user:pass@tcp(localhost:3306)/dbname"
                            "postgres://user:pass@host:port/dbname"
  -e, --excludes strings    comma-separated list of tables to exclude
  -l, --gen-data            enable generate data package code (default true)
  -k, --gen-main            enable generate main package code (default true)
  -z, --gen-orm             enable generate ORM code (default true)
  -q, --gen-proto           enable generate protobuf schema files (default true)
  -w, --gen-srv             enable generate server package code (default true)
  -a, --gen-svc             enable generate service package code (default true)
  -h, --help                help for sql2kratos
  -i, --includes strings    comma-separated list of tables to inspect (all if empty)
  -m, --module string       Target module name for the generated code, e.g., 'admin' (default "admin")
  -r, --orm string          ORM type to use (ent, gorm) (default "ent")
  -o, --output string       output path for protobuf schema files (default "./api/protos/")
  -p, --project string      Project name for the generated code, e.g., 'kratos-admin' (default "kratos-admin")
  -x, --repo                use repository pattern (default true)
  -g, --servers strings     comma-separated list of servers to generate, e.g., "grpc,rest" (default [grpc])
  -c, --service string      Service name for the generated code, e.g., 'user' (default "user")
  -s, --src-module string   Source module name, for REST service generate, e.g., "admin" (default "user")
  -v, --version string      Version of the module, e.g., 'v1' (default "v1")

示例

gRPC服务代码:

sql2kratos \
  -p "kratos-admin" \
  -n "postgres://postgres:pass@localhost:5432/test?sslmode=disable" \
  -r "ent" \
  -o "." \
  -m "user" \
  -c "user" \
  -g "grpc"

REST服务代码:

sql2kratos \
  -p "kratos-admin" \
  -n "postgres://postgres:pass@localhost:5432/test?sslmode=disable" \
  -r "ent" \
  -o "." \
  -s "user" \
  -m "admin" \
  -c "admin" \
  -g "rest" \
  -x=false \
  -z=false \
  -l=false

项目代码

目录
相关文章
|
19天前
|
前端开发 JavaScript Go
开箱即用的GO后台管理系统 Kratos Admin - 介绍
这是一个前后端分离的中台、后台,后端基于go、go-kratos、ent、gorm等,前端基于vue3、ts、Antdv、Vben开发。支持多租户、数据权限、动态Api、任务调度、OSS文件上传、滑块拼图验证、国内外主流数据库自由切换和动态高级查询。集成统一认证授权、事件总线、国际化、数据验证、分布式缓存、分布式事务、Ip限流、全Api鉴权、集成测试、性能分析、健康检查、接口文档等。
118 1
开箱即用的GO后台管理系统 Kratos Admin - 介绍
|
机器学习/深度学习 算法 存储
一文读懂大规模图神经网络平台AliGraph
2019阿里云峰会·上海开发者大会于7月24日盛大开幕,本次峰会与未来世界的开发者们分享开源大数据、IT基础设施云化、数据库、云原生、物联网等领域的技术干货, 共同探讨前沿科技趋势。本文整理自开源大数据专场中阿里巴巴资深技术专家李永先生的精彩演讲,将为大家分享AliGraph:大规模图神经网络平台。
8715 0
|
17天前
|
人工智能 监控 中间件
深入解析|Cursor编程实践经验分享
本文是近两个月的实践总结,结合在实际工作中的实践聊一聊Cursor的表现。记录在该过程中遇到的问题以及一些解法。问题概览(for 服务端): 不如我写的快?写的不符合预期? Cursor能完成哪些需求?这个需求可以用Cursor,那个需求不能用Cursor? 历史代码分析浅显,不够深入理解? 技术方案设计做的不够好,细节缺失,生成代码的可用性不够满意?
深入解析|Cursor编程实践经验分享
|
数据采集 安全 Windows
解决关于Windows Defender Antivirus Service自启造成运行python程序时,Windows的cpu和内存占用过高问题
启用“关闭Windwos defender”服务解决阿里云Windows服务器的卡顿问题,并列举了网上一些错误的解决方法。
12781 3
解决关于Windows Defender Antivirus Service自启造成运行python程序时,Windows的cpu和内存占用过高问题
|
2月前
|
监控 容灾 算法
阿里云 SLS 多云日志接入最佳实践:链路、成本与高可用性优化
本文探讨了如何高效、经济且可靠地将海外应用与基础设施日志统一采集至阿里云日志服务(SLS),解决全球化业务扩展中的关键挑战。重点介绍了高性能日志采集Agent(iLogtail/LoongCollector)在海外场景的应用,推荐使用LoongCollector以获得更优的稳定性和网络容错能力。同时分析了多种网络接入方案,包括公网直连、全球加速优化、阿里云内网及专线/CEN/VPN接入等,并提供了成本优化策略和多目标发送配置指导,帮助企业构建稳定、低成本、高可用的全球日志系统。
450 54
|
3月前
|
人工智能 运维 安全
函数计算支持热门 MCP Server 一键部署
云上托管 MCP 搭建 AI Agent 将成为趋势。函数计算 FC 目前已经支持开源 MCP Server 一键托管,欢迎体验。
906 114
|
2月前
|
数据采集 NoSQL API
零基础搭建免费IP代理池:从原理到实战的保姆级指南
本指南全面解析了代理池的核心价值、技术架构与实践应用。从突破反爬限制到提升访问效率,代理池在数据采集领域至关重要。内容涵盖环境搭建、核心配置解析、调度系统实现、运维优化及安全加固等环节。通过双进程架构与三重验证算法,确保代理稳定性;同时提供性能基准测试与典型问题解决方案。最后强调合规使用与混合架构部署策略,助力构建高可用、低延迟的专业级代理池,适用于大规模生产环境。
528 6
|
5月前
|
SQL JSON 关系型数据库
开箱即用的GO后台管理系统 Kratos Admin - 列表查询规则
Kratos Admin 是一个开箱即用的GO后台管理系统,支持通用列表查询请求。通过 `page`、`pageSize`、`query`(AND过滤)、`or`(OR过滤)、`orderBy`(排序)、`noPaging`(不分页)和 `fieldMask`(字段掩码)等参数,灵活配置查询条件。过滤规则遵循Python ORM风格,支持多种查找类型如 `in`、`gte`、`icontains` 等,适用于不同数据库。
76 1
|
前端开发 Go API
开箱即用的GO后台管理系统 Kratos Admin - 前端权限控制
Kratos Admin 是一个开箱即用的 GO 后台管理系统,前端权限管理分为路由和按钮权限。路由权限支持后端动态生成和前端固定配置两种方式,通过 `.env` 文件配置 `VITE_ROUTER_ACCESS_MODE` 实现。按钮权限可通过权限码或角色控制,支持组件、API 和指令三种方式。项目代码托管于 Gitee 和 Github。
149 0
IAR for STM8下载、安装、注册
IAR for STM8下载、安装、注册
1786 0