diff --git a/api/api.go b/api/api.go index be267221d8..7226b808f2 100644 --- a/api/api.go +++ b/api/api.go @@ -8,6 +8,7 @@ import ( "strings" "go-micro.dev/v4/api/router" + "go-micro.dev/v4/client" "go-micro.dev/v4/registry" "go-micro.dev/v4/server" ) @@ -35,6 +36,8 @@ type Options struct { Address string // Router for resolving routes Router router.Router + // Client to use for RPC + Client client.Client } // Option type are API option args. diff --git a/api/options.go b/api/options.go index 1af1d52cb6..edf714768f 100644 --- a/api/options.go +++ b/api/options.go @@ -2,6 +2,9 @@ package api import ( "go-micro.dev/v4/api/router" + registry2 "go-micro.dev/v4/api/router/registry" + "go-micro.dev/v4/client" + "go-micro.dev/v4/registry" ) func NewOptions(opts ...Option) Options { @@ -23,3 +26,12 @@ func WithRouter(r router.Router) Option { return nil } } + +// WithRegistry sets the api's client and router to use registry. +func WithRegistry(r registry.Registry) Option { + return func(o *Options) error { + o.Client = client.NewClient(client.Registry(r)) + o.Router = registry2.NewRouter(router.WithRegistry(r)) + return nil + } +}