Created
June 11, 2019 08:33
-
-
Save vtolstov/e7b59191604120c49b007416cc319261 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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