1
0
mirror of https://github.com/go-micro/go-micro.git synced 2024-12-12 08:23:58 +02:00
go-micro/plugins/registry/multi/options.go
2021-10-12 12:55:53 +01:00

31 lines
660 B
Go

package multi
import (
"context"
"go-micro.dev/v4/registry"
)
type writeKey struct{}
type readKey struct{}
// helper for setting registry options
func setRegistryOption(k, v interface{}) registry.Option {
return func(o *registry.Options) {
if o.Context == nil {
o.Context = context.Background()
}
o.Context = context.WithValue(o.Context, k, v)
}
}
// WriteRegistry add underlining registries
func WriteRegistry(w ...registry.Registry) registry.Option {
return setRegistryOption(writeKey{}, w)
}
// ReadRegistry add underlining registries
func ReadRegistry(r ...registry.Registry) registry.Option {
return setRegistryOption(readKey{}, r)
}