mirror of
https://github.com/DeBrosOfficial/network.git
synced 2025-10-06 13:49:07 +00:00
The changes reorganize the network client code by splitting it into focused modules for better maintainability, including
33 lines
911 B
Go
33 lines
911 B
Go
package client
|
|
|
|
import (
|
|
"context"
|
|
|
|
"git.debros.io/DeBros/network/pkg/pubsub"
|
|
)
|
|
|
|
// pubSubBridge bridges between our PubSubClient interface and the pubsub package
|
|
type pubSubBridge struct {
|
|
adapter *pubsub.ClientAdapter
|
|
}
|
|
|
|
func (p *pubSubBridge) Subscribe(ctx context.Context, topic string, handler MessageHandler) error {
|
|
// 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 {
|
|
return p.adapter.Publish(ctx, topic, data)
|
|
}
|
|
|
|
func (p *pubSubBridge) Unsubscribe(ctx context.Context, topic string) error {
|
|
return p.adapter.Unsubscribe(ctx, topic)
|
|
}
|
|
|
|
func (p *pubSubBridge) ListTopics(ctx context.Context) ([]string, error) {
|
|
return p.adapter.ListTopics(ctx)
|
|
}
|