Skip to content

Instantly share code, notes, and snippets.

@vtolstov
Created June 11, 2019 08:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vtolstov/e7b59191604120c49b007416cc319261 to your computer and use it in GitHub Desktop.
Save vtolstov/e7b59191604120c49b007416cc319261 to your computer and use it in GitHub Desktop.
package multi
import (
"context"
"github.com/micro/go-micro/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)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment