chore: stabilize lint and verify builds
This commit is contained in:
@@ -6,7 +6,7 @@ const (
|
||||
Go contracts.Channel = "go"
|
||||
Kafka contracts.Channel = "kafka"
|
||||
Redis contracts.Channel = "redis"
|
||||
Sql contracts.Channel = "sql"
|
||||
SQL contracts.Channel = "sql"
|
||||
)
|
||||
|
||||
type DefaultPublishTo struct{}
|
||||
|
||||
@@ -2,6 +2,7 @@ package event
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"github.com/ThreeDotsLabs/watermill"
|
||||
"github.com/ThreeDotsLabs/watermill/message"
|
||||
@@ -22,12 +23,12 @@ func DefaultProvider() container.ProviderContainer {
|
||||
}
|
||||
|
||||
type Config struct {
|
||||
Sql *ConfigSql
|
||||
SQL *ConfigSQL
|
||||
Kafka *ConfigKafka
|
||||
Redis *ConfigRedis
|
||||
}
|
||||
|
||||
type ConfigSql struct {
|
||||
type ConfigSQL struct {
|
||||
ConsumerGroup string
|
||||
}
|
||||
|
||||
@@ -50,24 +51,26 @@ type PubSub struct {
|
||||
|
||||
func (ps *PubSub) Serve(ctx context.Context) error {
|
||||
if err := ps.Router.Run(ctx); err != nil {
|
||||
return err
|
||||
return fmt.Errorf("run event router: %w", err)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// publish
|
||||
func (ps *PubSub) Publish(e contracts.EventPublisher) error {
|
||||
if e == nil {
|
||||
func (ps *PubSub) Publish(event contracts.EventPublisher) error {
|
||||
if event == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
payload, err := e.Marshal()
|
||||
payload, err := event.Marshal()
|
||||
if err != nil {
|
||||
return err
|
||||
return fmt.Errorf("marshal event payload: %w", err)
|
||||
}
|
||||
|
||||
msg := message.NewMessage(watermill.NewUUID(), payload)
|
||||
return ps.getPublisher(e.Channel()).Publish(e.Topic(), msg)
|
||||
|
||||
return ps.getPublisher(event.Channel()).Publish(event.Topic(), msg)
|
||||
}
|
||||
|
||||
// getPublisher returns the publisher for the specified channel.
|
||||
@@ -75,6 +78,7 @@ func (ps *PubSub) getPublisher(channel contracts.Channel) message.Publisher {
|
||||
if pub, ok := ps.publishers[channel]; ok {
|
||||
return pub
|
||||
}
|
||||
|
||||
return ps.publishers[Go]
|
||||
}
|
||||
|
||||
@@ -82,6 +86,7 @@ func (ps *PubSub) getSubscriber(channel contracts.Channel) message.Subscriber {
|
||||
if sub, ok := ps.subscribers[channel]; ok {
|
||||
return sub
|
||||
}
|
||||
|
||||
return ps.subscribers[Go]
|
||||
}
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@ package event
|
||||
|
||||
import (
|
||||
"github.com/ThreeDotsLabs/watermill"
|
||||
"github.com/sirupsen/logrus"
|
||||
logrus "github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
// LogrusLoggerAdapter is a watermill logger adapter for logrus.
|
||||
|
||||
@@ -78,7 +78,7 @@ func ProvideChannel(opts ...opt.Option) error {
|
||||
publishers[Redis] = redisPublisher
|
||||
}
|
||||
|
||||
if config.Sql == nil {
|
||||
if config.SQL == nil {
|
||||
var db *sqlDB.DB
|
||||
sqlPublisher, err := sql.NewPublisher(db, sql.PublisherConfig{
|
||||
SchemaAdapter: sql.DefaultPostgreSQLSchema{},
|
||||
@@ -87,16 +87,16 @@ func ProvideChannel(opts ...opt.Option) error {
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
publishers[Sql] = sqlPublisher
|
||||
publishers[SQL] = sqlPublisher
|
||||
|
||||
sqlSubscriber, err := sql.NewSubscriber(db, sql.SubscriberConfig{
|
||||
SchemaAdapter: sql.DefaultPostgreSQLSchema{},
|
||||
ConsumerGroup: config.Sql.ConsumerGroup,
|
||||
ConsumerGroup: config.SQL.ConsumerGroup,
|
||||
}, logger)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
subscribers[Sql] = sqlSubscriber
|
||||
subscribers[SQL] = sqlSubscriber
|
||||
}
|
||||
|
||||
router, err := message.NewRouter(message.RouterConfig{}, logger)
|
||||
|
||||
Reference in New Issue
Block a user