优化结构

This commit is contained in:
Yvan
2026-08-22 11:26:58 +08:00
parent 54f76bd913
commit d987244d0e
8 changed files with 53 additions and 43 deletions
+5 -17
View File
@@ -6,7 +6,6 @@ package module
import (
"github.com/gin-gonic/gin"
"kra/pkg/database/migration"
"kra/pkg/mq"
"kra/pkg/task"
)
@@ -30,12 +29,11 @@ type TimedTask struct {
}
type Definition struct {
Name string
Migrations []migration.Step
Surface Surface
TimedTasks []TimedTask
Tasks []task.Method
SubscriptionContributors []mq.SubscriptionContributor
Name string
Migrations []migration.Step
Surface Surface
TimedTasks []TimedTask
Tasks []task.Method
}
type Catalog struct {
@@ -75,16 +73,6 @@ func (c Catalog) TaskMethods() []task.Method {
return methods
}
// SubscriptionContributors returns the module declarations that are applied
// to the process-wide MQ runtime during application startup.
func (c Catalog) SubscriptionContributors() []mq.SubscriptionContributor {
var contributors []mq.SubscriptionContributor
for _, item := range c.Definitions {
contributors = append(contributors, item.SubscriptionContributors...)
}
return contributors
}
type RouteRegistrar interface {
RegisterRoutes(public, private *gin.RouterGroup, engine *gin.Engine)
}
+9
View File
@@ -191,6 +191,9 @@ func (c *RabbitMQ) Publish(ctx context.Context, topic string, payload []byte, qo
if c == nil {
return ErrUnavailable
}
if ctx == nil {
ctx = context.Background()
}
if c != nil && strings.TrimSpace(topic) == "" {
topic = c.config.RoutingKey
}
@@ -231,6 +234,9 @@ func (c *RabbitMQ) Subscribe(ctx context.Context, topic string, qos byte, handle
if c == nil {
return ErrUnavailable
}
if ctx == nil {
ctx = context.Background()
}
if c != nil && strings.TrimSpace(topic) == "" {
topic = c.config.RoutingKey
}
@@ -331,6 +337,9 @@ func (c *RabbitMQ) Unsubscribe(ctx context.Context, topics ...string) error {
if c == nil {
return ErrUnavailable
}
if ctx == nil {
ctx = context.Background()
}
if len(topics) == 0 {
return errors.New("rabbitmq routing keys are empty")
}