mirror of
https://github.com/go-micro/go-micro.git
synced 2024-11-24 08:02:32 +02:00
fix(api): add WithRegistry option for api (#2618)
This commit is contained in:
parent
521e6b644c
commit
e337eb2c3d
@ -8,6 +8,7 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"go-micro.dev/v4/api/router"
|
"go-micro.dev/v4/api/router"
|
||||||
|
"go-micro.dev/v4/client"
|
||||||
"go-micro.dev/v4/registry"
|
"go-micro.dev/v4/registry"
|
||||||
"go-micro.dev/v4/server"
|
"go-micro.dev/v4/server"
|
||||||
)
|
)
|
||||||
@ -35,6 +36,8 @@ type Options struct {
|
|||||||
Address string
|
Address string
|
||||||
// Router for resolving routes
|
// Router for resolving routes
|
||||||
Router router.Router
|
Router router.Router
|
||||||
|
// Client to use for RPC
|
||||||
|
Client client.Client
|
||||||
}
|
}
|
||||||
|
|
||||||
// Option type are API option args.
|
// Option type are API option args.
|
||||||
|
@ -2,6 +2,9 @@ package api
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"go-micro.dev/v4/api/router"
|
"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 {
|
func NewOptions(opts ...Option) Options {
|
||||||
@ -23,3 +26,12 @@ func WithRouter(r router.Router) Option {
|
|||||||
return nil
|
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
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user