mirror of
https://github.com/go-micro/go-micro.git
synced 2025-06-12 22:07:47 +02:00
add context to server.SubscriberOptions and broker.SubscribeOption
Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
This commit is contained in:
@ -1,13 +1,20 @@
|
||||
package server
|
||||
|
||||
import "context"
|
||||
|
||||
type HandlerOption func(*HandlerOptions)
|
||||
|
||||
type HandlerOptions struct {
|
||||
Internal bool
|
||||
Metadata map[string]map[string]string
|
||||
}
|
||||
|
||||
type SubscriberOption func(*SubscriberOptions)
|
||||
|
||||
type SubscriberOptions struct {
|
||||
Queue string
|
||||
Internal bool
|
||||
Context context.Context
|
||||
}
|
||||
|
||||
// EndpointMetadata is a Handler option that allows metadata to be added to
|
||||
@ -34,6 +41,17 @@ func InternalSubscriber(b bool) SubscriberOption {
|
||||
o.Internal = b
|
||||
}
|
||||
}
|
||||
func NewSubscriberOptions(opts ...SubscriberOption) SubscriberOptions {
|
||||
opt := SubscriberOptions{
|
||||
Context: context.Background(),
|
||||
}
|
||||
|
||||
for _, o := range opts {
|
||||
o(&opt)
|
||||
}
|
||||
|
||||
return opt
|
||||
}
|
||||
|
||||
// Shared queue name distributed messages across subscribers
|
||||
func SubscriberQueue(n string) SubscriberOption {
|
||||
@ -41,3 +59,10 @@ func SubscriberQueue(n string) SubscriberOption {
|
||||
o.Queue = n
|
||||
}
|
||||
}
|
||||
|
||||
// SubscriberContext set context options to allow broker SubscriberOption passed
|
||||
func SubscriberContext(ctx context.Context) SubscriberOption {
|
||||
return func(o *SubscriberOptions) {
|
||||
o.Context = ctx
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user