Skip to content

Commit

Permalink
fix(api): add WithRegistry option for api (#2618)
Browse files Browse the repository at this point in the history
  • Loading branch information
AWaterColorPen authored Mar 7, 2023
1 parent 521e6b6 commit e337eb2
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
3 changes: 3 additions & 0 deletions api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down Expand Up @@ -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.
Expand Down
12 changes: 12 additions & 0 deletions api/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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
}
}

0 comments on commit e337eb2

Please sign in to comment.