mirror of
https://github.com/DeBrosOfficial/network.git
synced 2025-10-06 12:29:07 +00:00
Here's the commit message: ``` Fix code style and indentation Apply consistent indentation, fix whitespace and tabs vs spaces issues, remove trailing whitespace, and ensure proper line endings throughout the codebase. Also add comments and improve code organization. ``` The message body is included since this is a bigger cleanup effort that touched multiple files and made various formatting improvements that are worth explaining.
47 lines
1.5 KiB
Go
47 lines
1.5 KiB
Go
package client
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
|
|
"git.debros.io/DeBros/network/pkg/pubsub"
|
|
)
|
|
|
|
// pubSubBridge bridges between our PubSubClient interface and the pubsub package
|
|
type pubSubBridge struct {
|
|
client *Client
|
|
adapter *pubsub.ClientAdapter
|
|
}
|
|
|
|
func (p *pubSubBridge) Subscribe(ctx context.Context, topic string, handler MessageHandler) error {
|
|
if err := p.client.requireAccess(ctx); err != nil {
|
|
return fmt.Errorf("authentication required: %w - run CLI commands to authenticate automatically", err)
|
|
}
|
|
// Convert our MessageHandler to the pubsub package MessageHandler
|
|
pubsubHandler := func(topic string, data []byte) error {
|
|
return handler(topic, data)
|
|
}
|
|
return p.adapter.Subscribe(ctx, topic, pubsubHandler)
|
|
}
|
|
|
|
func (p *pubSubBridge) Publish(ctx context.Context, topic string, data []byte) error {
|
|
if err := p.client.requireAccess(ctx); err != nil {
|
|
return fmt.Errorf("authentication required: %w - run CLI commands to authenticate automatically", err)
|
|
}
|
|
return p.adapter.Publish(ctx, topic, data)
|
|
}
|
|
|
|
func (p *pubSubBridge) Unsubscribe(ctx context.Context, topic string) error {
|
|
if err := p.client.requireAccess(ctx); err != nil {
|
|
return fmt.Errorf("authentication required: %w - run CLI commands to authenticate automatically", err)
|
|
}
|
|
return p.adapter.Unsubscribe(ctx, topic)
|
|
}
|
|
|
|
func (p *pubSubBridge) ListTopics(ctx context.Context) ([]string, error) {
|
|
if err := p.client.requireAccess(ctx); err != nil {
|
|
return nil, fmt.Errorf("authentication required: %w - run CLI commands to authenticate automatically", err)
|
|
}
|
|
return p.adapter.ListTopics(ctx)
|
|
}
|