Skip to content

Commit 241b39c

Browse files
committed
feat(config): update rabbit config path and improve command descriptions
- Change default rabbit config path from `~/.rabbit` to `./.rabbit/` - Update Dockerfile to use absolute paths for volume mounts and CMD arguments - Enhance CLI command help texts with detailed descriptions and usage scenarios - Refactor config loading logic in send commands to use kratos config sources - Improve path normalization in client config generation - Remove obsolete config fields and consolidate configuration handling - Add metadata fields to server config including repository, author and email - Update dependencies and clean up unused imports and code sections
1 parent a23d9bc commit 241b39c

Some content is hidden

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

49 files changed

+1967
-1487
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,4 +39,5 @@ go.work.sum
3939

4040
# deploy
4141
deploy/*/data
42-
description.txt
42+
description.txt
43+
.rabbit/

Dockerfile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,11 @@ USER appuser
4949

5050
# 设置卷
5151
VOLUME /moon/config
52-
VOLUME ~/.rabbit
52+
VOLUME /moon/.rabbit
5353

5454
# 暴露端口
5555
EXPOSE 8080
5656
EXPOSE 9090
5757

5858
# 运行应用
59-
CMD ["rabbit", "run", "-c", "/moon/config", "-o", "~/.rabbit"]
59+
CMD ["rabbit", "run", "-c", "/moon/config/", "--rabbit-config", "/moon/.rabbit/"]

cmd/cmd.go

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,32 @@ func NewCmd() *cobra.Command {
2525
rootCmd := &cobra.Command{
2626
Use: "rabbit",
2727
Short: "Moon messaging platform - Rabbit service",
28-
Long: `Rabbit is a messaging service for the Moon platform.
29-
30-
This service provides message handling capabilities for the Moon ecosystem,
31-
including message routing, delivery, and management features.`,
28+
Long: `Rabbit(玉兔)是 Moon 平台的消息服务工具,提供统一的消息发送和管理能力。
29+
30+
Rabbit 是一个基于 Kratos 框架构建的分布式消息服务平台,支持多种消息通道
31+
(邮件、Webhook、短信、飞书等)的统一管理和发送。通过命名空间(Namespace)
32+
实现多租户隔离,支持配置文件和数据库两种存储模式,满足不同场景的部署需求。
33+
34+
核心能力:
35+
• 多通道消息发送:支持邮件、Webhook、短信、飞书等多种消息通道的统一管理
36+
• 模板化发送:支持消息模板配置,实现消息内容的动态渲染和复用
37+
• 异步消息处理:基于消息队列实现异步发送,提升系统吞吐量和可靠性
38+
• 配置管理:支持邮件服务器、Webhook 端点等通道配置的集中管理
39+
• 多租户隔离:通过命名空间实现不同业务或租户的配置和数据隔离
40+
• 命令行工具:提供丰富的 CLI 命令,支持服务管理、消息发送、配置生成等
41+
42+
命令分类:
43+
• Basic Commands(基础命令):config、version 等基础操作
44+
• Message Commands(消息命令):send、apply、get、delete 等消息相关操作
45+
• Service Commands(服务命令):run 等服务管理操作
46+
47+
使用场景:
48+
• 企业级通知系统:统一管理各类业务通知(订单、告警、系统消息等)
49+
• 微服务消息中心:为微服务架构提供统一的消息发送能力
50+
• 多渠道推送平台:集成多种消息通道,实现消息的统一发送和管理
51+
• 开发测试工具:通过命令行快速测试消息通道配置和发送功能
52+
53+
使用 "rabbit [command] --help" 查看具体命令的详细说明。`,
3254
Run: func(cmd *cobra.Command, args []string) {
3355
cmd.Help()
3456
},

cmd/config/config.go

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,24 @@ func NewCmd(configContent []byte) *cobra.Command {
1919
configCmd := &cobra.Command{
2020
Use: "config",
2121
Short: "Generate default server.yaml configuration file",
22-
Long: `Generate a default server.yaml configuration file in the specified path.
22+
Long: `生成 Rabbit 服务的默认配置文件,用于快速初始化和部署。
2323
24-
This command will create a server.yaml file with default configuration values.
25-
If the target file already exists and --force is not set, it will be renamed with a timestamp suffix.
26-
If --force is set, the existing file will be overwritten.`,
24+
config 命令会在指定路径生成 server.yaml 配置文件,包含服务运行所需
25+
的默认配置项,如服务器端口、数据库连接、日志级别等。
26+
27+
主要功能:
28+
• 默认配置生成:自动生成包含所有必需配置项的配置文件
29+
• 安全备份:如果目标文件已存在,自动备份为带时间戳的文件
30+
• 强制覆盖:支持 --force 参数强制覆盖已存在的配置文件
31+
• 路径自定义:支持指定配置文件的生成路径和文件名
32+
33+
使用场景:
34+
• 快速初始化:新部署环境时快速生成配置文件
35+
• 配置模板:作为配置模板参考,了解所有可配置项
36+
• 配置迁移:在不同环境间迁移配置时作为起点
37+
38+
生成的配置文件包含服务器、数据库、日志、消息通道等各个模块的配置
39+
项,可根据实际环境进行修改和调整。`,
2740
Annotations: map[string]string{
2841
"group": cmd.BasicCommands,
2942
},

cmd/global.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ type GlobalFlags struct {
2727

2828
func (g *GlobalFlags) addFlags(cmd *cobra.Command) {
2929
cmd.PersistentFlags().StringVarP(&g.Namespace, "namespace", "n", "", "The namespace of the service")
30-
cmd.PersistentFlags().StringVar(&g.RabbitConfigPath, "rabbit-config", "~/.rabbit", "The config file of the rabbit")
30+
cmd.PersistentFlags().StringVar(&g.RabbitConfigPath, "rabbit-config", "./.rabbit/", "The config file of the rabbit")
3131
}
3232

3333
type GlobalOption func(*GlobalFlags)

cmd/gorm/flags.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ func (f *Flags) addFlags(c *cobra.Command) {
4343

4444
// containsNamespace 检查 namespace 是否在逗号分隔的 namespaces 字符串中
4545
func containsNamespace(namespaces, target string) bool {
46-
for _, ns := range strings.Split(namespaces, ",") {
46+
for _, ns := range strutil.SplitSkipEmpty(namespaces, ",") {
4747
if strings.TrimSpace(ns) == target {
4848
return true
4949
}

cmd/run/client.go

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ func generateClientConfig(
8282
endpoint = strings.Join([]string{"discovery://", serverName}, "/")
8383
protocol = config.ClusterConfig_GRPC
8484
} else {
85+
protocol = config.ClusterConfig_GRPC
8586
endpoint = normalizeAddress(grpcEndpoint)
8687
if endpoint == "" {
8788
endpoint = normalizeAddress(httpEndpoint)
@@ -110,13 +111,13 @@ func generateClientConfig(
110111
}
111112
}
112113

113-
// 写入配置文件到当前目录的 .rabbit/config.yaml
114-
configDir := filepath.Dir(load.ExpandHomeDir(flags.clientConfigOutputPath))
114+
// 写入配置文件到当前目录的 .rabbit/client_config.yaml
115+
configDir := filepath.Dir(load.ExpandHomeDir(flags.RabbitConfigPath))
115116
if err := os.MkdirAll(configDir, 0o755); err != nil {
116117
return fmt.Errorf("create config directory failed: %w", err)
117118
}
118119

119-
configFile := filepath.Join(configDir, "config.yaml")
120+
configFile := filepath.Join(configDir, "client_config.yaml")
120121

121122
// 转换为 YAML 格式
122123
yamlData, err := clientConfigToYAML(clientConfig)
@@ -133,10 +134,22 @@ func generateClientConfig(
133134
return nil
134135
}
135136

136-
// normalizeAddress 将地址中的 0.0.0.0 转换为 localhost
137+
// normalizeAddress 将地址中的 0.0.0.0 转换为 localhost,并移除协议前缀
137138
func normalizeAddress(addr string) string {
139+
if addr == "" {
140+
return addr
141+
}
142+
// 移除协议前缀
143+
protocols := []string{"https://", "http://", "grpcs://", "grpc://"}
144+
for _, protocol := range protocols {
145+
if strings.HasPrefix(addr, protocol) {
146+
addr = strings.TrimPrefix(addr, protocol)
147+
break
148+
}
149+
}
150+
// 将 0.0.0.0 转换为 localhost
138151
if strings.HasPrefix(addr, "0.0.0.0:") {
139-
return strings.Replace(addr, "0.0.0.0:", "localhost:", 1)
152+
addr = strings.Replace(addr, "0.0.0.0:", "localhost:", 1)
140153
}
141154
return addr
142155
}

cmd/run/flags.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,7 @@ import (
1616

1717
type Flags struct {
1818
cmd.GlobalFlags
19-
configPath string
20-
clientConfigOutputPath string
19+
configPath string
2120

2221
*conf.Bootstrap
2322
environment string
@@ -33,7 +32,6 @@ var flags Flags
3332
func (f *Flags) addFlags(c *cobra.Command, bc *conf.Bootstrap) {
3433
f.Bootstrap = bc
3534
c.Flags().StringVarP(&f.configPath, "config", "c", "", `Example: -c=./config/, --config="./config/"`)
36-
c.Flags().StringVarP(&f.clientConfigOutputPath, "client-config-output", "o", "~/.rabbit/", `Example: -o=./client/, --client-config-output="~/.rabbit/"`)
3735

3836
c.Flags().StringVar(&f.environment, "environment", f.Environment.String(), `Example: --environment="DEV", --environment="TEST", --environment="PREVIEW", --environment="PROD"`)
3937
c.Flags().StringVar(&f.Server.Http.Address, "http-address", f.Server.Http.Address, `Example: --http-address="0.0.0.0:8080", --http-address=":8080"`)

cmd/run/run.go

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,25 @@ func NewCmd(defaultServerConfigBytes []byte) *cobra.Command {
2222
runCmd := &cobra.Command{
2323
Use: "run",
2424
Short: "Run the Rabbit service",
25-
Long: `A longer description that spans multiple lines and likely contains examples and usage of using your command.`,
25+
Long: `启动 Rabbit 消息服务,提供统一的消息发送和管理能力。
26+
27+
Rabbit 是一个基于 Kratos 框架构建的分布式消息服务平台,支持多种消息通道
28+
(邮件、Webhook、短信等)的统一管理和发送。通过命名空间(Namespace)实现
29+
多租户隔离,支持配置文件和数据库两种存储模式,满足不同场景的部署需求。
30+
31+
主要功能:
32+
• 多通道消息发送:支持邮件、Webhook、短信等多种消息通道的统一管理
33+
• 模板化发送:支持消息模板配置,实现消息内容的动态渲染和复用
34+
• 异步消息处理:基于消息队列实现异步发送,提升系统吞吐量和可靠性
35+
• 配置管理:支持邮件服务器、Webhook 端点等通道配置的集中管理
36+
• 多租户隔离:通过命名空间实现不同业务或租户的配置和数据隔离
37+
38+
使用场景:
39+
• 企业级通知系统:统一管理各类业务通知(订单、告警、系统消息等)
40+
• 微服务消息中心:为微服务架构提供统一的消息发送能力
41+
• 多渠道推送平台:集成多种消息通道,实现消息的统一发送和管理
42+
43+
启动服务后,Rabbit 将监听配置的端口,提供 HTTP/gRPC API 接口供客户端调用。`,
2644
Annotations: map[string]string{
2745
"group": cmd.ServiceCommands,
2846
},
@@ -49,6 +67,7 @@ func NewCmd(defaultServerConfigBytes []byte) *cobra.Command {
4967

5068
func runServer(_ *cobra.Command, _ []string) {
5169
flags.GlobalFlags = cmd.GetGlobalFlags()
70+
flags.applyToBootstrap()
5271
var bc conf.Bootstrap
5372
if strutil.IsNotEmpty(flags.configPath) {
5473
c := config.New(config.WithSource(
@@ -67,7 +86,6 @@ func runServer(_ *cobra.Command, _ []string) {
6786
flags.Bootstrap = &bc
6887
}
6988

70-
flags.applyToBootstrap()
7189
serverConf := flags.GetServer()
7290
envOpts := []hello.Option{
7391
hello.WithVersion(flags.Version),

cmd/send/email/email.go

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,25 @@ func NewCmd() *cobra.Command {
1111
emailCmd := &cobra.Command{
1212
Use: "email",
1313
Short: "Send an email message",
14-
Long: `A longer description that spans multiple lines and likely contains examples
15-
and usage of using your command.`,
14+
Long: `发送邮件消息,支持 HTML 和纯文本格式,可配置邮件服务器。
15+
16+
email 命令用于直接发送邮件消息,支持指定邮件配置 ID、收件人、主题、
17+
内容等参数,可以快速发送单封邮件或使用模板发送。
18+
19+
主要功能:
20+
• 邮件发送:通过配置的邮件服务器发送邮件消息
21+
• 格式支持:支持 HTML 和纯文本两种邮件格式
22+
• 模板发送:支持使用预配置的邮件模板进行发送
23+
• 附件支持:支持添加邮件附件(如需要)
24+
• 抄送密送:支持设置收件人、抄送、密送等邮件头
25+
26+
使用场景:
27+
• 测试邮件:测试邮件服务器配置是否正确
28+
• 紧急通知:需要立即发送的重要邮件通知
29+
• 单封发送:发送单封邮件,无需通过队列
30+
31+
邮件发送需要先配置邮件服务器(SMTP),可通过配置文件或 API 进行
32+
配置。发送的邮件会立即处理,适合测试和紧急场景。`,
1633
Annotations: map[string]string{
1734
"group": cmd.MessageCommands,
1835
},

0 commit comments

Comments
 (0)