Add repository guidelines and enhance documentation for project structure, build commands, coding standards, and testing practices. Introduce AGENTS.md for contributor guidance, update README.md to reference new guidelines, and improve configuration documentation for NATS modes. Update Makefile and Taskfile with clearer run commands and requirements for development and production modes. Add production deployment guide and improve logging configuration for better observability.

This commit is contained in:
windyboy
2025-11-17 16:25:23 +08:00
parent 67abd66fa3
commit 704c7b80f6
34 changed files with 2976 additions and 782 deletions
+63 -1
View File
@@ -20,12 +20,17 @@ type Publisher struct {
logger *zap.Logger
}
// ProvidePublisher creates a NATS publisher
// ProvidePublisher creates a NATS publisher.
// When js is nil (core mode), returns a CorePublisher that uses plain NATS.
func ProvidePublisher(
js nats.JetStreamContext,
nc *nats.Conn,
cfg *config.Config,
logger *zap.Logger,
) (port.Publisher, error) {
if js == nil {
return ProvideCorePublisher(nc, cfg, logger)
}
return &Publisher{
js: js,
cfg: cfg,
@@ -33,6 +38,63 @@ func ProvidePublisher(
}, nil
}
// CorePublisher publishes messages to plain NATS (non-JetStream)
type CorePublisher struct {
conn *nats.Conn
cfg *config.Config
logger *zap.Logger
}
// ProvideCorePublisher creates a NATS publisher for core mode
func ProvideCorePublisher(
conn *nats.Conn,
cfg *config.Config,
logger *zap.Logger,
) (port.Publisher, error) {
return &CorePublisher{
conn: conn,
cfg: cfg,
logger: logger,
}, nil
}
// Publish publishes a message using plain NATS
func (p *CorePublisher) Publish(message interface{}) error {
topic := p.cfg.Publisher.Topic
if topic == "" {
p.logger.Error("publisher topic is not configured")
return fmt.Errorf("publisher topic is not configured")
}
// Marshal message to JSON
messageBytes, err := json.Marshal(message)
if err != nil {
p.logger.Error("failed to marshal message",
zap.String("topic", topic),
zap.Error(err),
)
return fmt.Errorf("failed to marshal message: %w", err)
}
// Publish to plain NATS
err = p.conn.Publish(topic, messageBytes)
if err != nil {
p.logger.Error("failed to publish message",
zap.String("topic", topic),
zap.Int("message_size", len(messageBytes)),
zap.Error(err),
)
return fmt.Errorf("failed to publish message: %w", err)
}
p.logger.Debug("Published message",
zap.String("topic", topic),
zap.Int("size", len(messageBytes)),
)
return nil
}
// Publish publishes a message
func (p *Publisher) Publish(message interface{}) error {
topic := p.cfg.Publisher.Topic