优化结构
This commit is contained in:
+5
-17
@@ -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)
|
||||
}
|
||||
|
||||
@@ -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")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user