1
0
mirror of https://github.com/go-micro/go-micro.git synced 2024-12-18 08:26:38 +02:00
go-micro/api/options.go
2024-06-04 21:40:43 +01:00

46 lines
902 B
Go

package api
import (
"go-micro.dev/v5/api/router"
registry2 "go-micro.dev/v5/api/router/registry"
"go-micro.dev/v5/client"
"go-micro.dev/v5/registry"
)
func NewOptions(opts ...Option) Options {
options := Options{
Address: ":8080",
}
for _, o := range opts {
o(&options)
}
return options
}
// WithAddress sets the address to listen
func WithAddress(addr string) Option {
return func(o *Options) error {
o.Address = addr
return nil
}
}
// 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
}
}
// 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
}
}