diff --git a/api/api.go b/api/api.go index 36978a82..5bebb1eb 100644 --- a/api/api.go +++ b/api/api.go @@ -7,20 +7,21 @@ import ( "regexp" "strings" + "go-micro.dev/v4/api/router" "go-micro.dev/v4/registry" "go-micro.dev/v4/server" ) -// The Api interface provides a way to +// The Api interface provides a way to // create composable API gateways type Api interface { // Initialise options Init(...Option) error // Get the options Options() Options - // Register an endpoint + // Register an endpoint Register(*Endpoint) error - // Deregister an endpoint + // Deregister an endpoint Deregister(*Endpoint) error // Run the api Run(context.Context) error @@ -31,6 +32,8 @@ type Api interface { type Options struct { // Address of the server Address string + // Router for resolving routes + Router router.Router } type Option func(*Options) error diff --git a/api/default.go b/api/default.go index 18ffed55..c4c111f7 100644 --- a/api/default.go +++ b/api/default.go @@ -19,8 +19,12 @@ type api struct { func newApi(opts ...Option) Api { options := NewOptions(opts...) - // TODO: make configurable - rtr := registry.NewRouter() + rtr := options.Router + + if rtr == nil { + // TODO: make configurable + rtr = registry.NewRouter() + } // TODO: make configurable hdlr := rpc.NewHandler( diff --git a/api/options.go b/api/options.go index 210f947b..c52c918f 100644 --- a/api/options.go +++ b/api/options.go @@ -1,5 +1,9 @@ package api +import ( + "go-micro.dev/v4/api/router" +) + func NewOptions(opts ...Option) Options { options := Options{ Address: ":8080", @@ -11,3 +15,11 @@ func NewOptions(opts ...Option) Options { return options } + +// WithRouter sets the router to use e.g static or registry +func WithRouter(r router.Router) Option { + return func(o *Options) error { + o.Router = r + return nil + } +}