2022-07-02 13:11:59 +02:00
|
|
|
package api
|
|
|
|
|
2022-07-02 15:15:02 +02:00
|
|
|
import (
|
2024-06-04 22:40:43 +02:00
|
|
|
"go-micro.dev/v5/api/router"
|
|
|
|
registry2 "go-micro.dev/v5/api/router/registry"
|
|
|
|
"go-micro.dev/v5/client"
|
|
|
|
"go-micro.dev/v5/registry"
|
2022-07-02 15:15:02 +02:00
|
|
|
)
|
|
|
|
|
2022-07-02 13:11:59 +02:00
|
|
|
func NewOptions(opts ...Option) Options {
|
|
|
|
options := Options{
|
|
|
|
Address: ":8080",
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, o := range opts {
|
|
|
|
o(&options)
|
|
|
|
}
|
|
|
|
|
|
|
|
return options
|
|
|
|
}
|
2022-07-02 15:15:02 +02:00
|
|
|
|
2023-12-18 12:29:47 +02:00
|
|
|
// WithAddress sets the address to listen
|
|
|
|
func WithAddress(addr string) Option {
|
|
|
|
return func(o *Options) error {
|
|
|
|
o.Address = addr
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-09-30 16:27:07 +02:00
|
|
|
// WithRouter sets the router to use e.g static or registry.
|
2022-07-02 15:15:02 +02:00
|
|
|
func WithRouter(r router.Router) Option {
|
|
|
|
return func(o *Options) error {
|
|
|
|
o.Router = r
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
}
|
2023-03-07 18:05:25 +02:00
|
|
|
|
|
|
|
// 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
|
|
|
|
}
|
|
|
|
}
|