1
0
mirror of https://github.com/go-micro/go-micro.git synced 2024-12-12 08:23:58 +02:00
go-micro/runtime/options.go

99 lines
1.8 KiB
Go
Raw Normal View History

2019-09-24 19:32:35 +02:00
package runtime
2019-09-24 20:00:11 +02:00
import (
"io"
)
type Option func(o *Options)
// Options configure runtime
type Options struct {
// Notifier for updates
Notifier Notifier
2019-11-29 13:35:00 +02:00
// Service type to manage
Type string
}
2019-11-29 13:35:00 +02:00
// WithNotifier specifies a notifier for updates
func WithNotifier(n Notifier) Option {
return func(o *Options) {
o.Notifier = n
}
}
2019-11-29 13:35:00 +02:00
// WithType sets the service type to manage
func WithType(t string) Option {
return func(o *Options) {
o.Type = t
}
}
2019-09-24 19:32:35 +02:00
type CreateOption func(o *CreateOptions)
2019-11-29 13:35:00 +02:00
type ReadOption func(o *ReadOptions)
// CreateOptions configure runtime services
2019-09-24 19:32:35 +02:00
type CreateOptions struct {
// command to execute including args
Command []string
// Environment to configure
Env []string
2019-09-24 20:00:11 +02:00
// Log output
Output io.Writer
2019-11-29 13:35:00 +02:00
// Type of service to create
Type string
}
// ReadOptions queries runtime services
type ReadOptions struct {
// Service name
Service string
// Version queries services with given version
Version string
// Type of service
Type string
2019-09-24 19:32:35 +02:00
}
2019-09-24 20:00:11 +02:00
// WithCommand specifies the command to execute
2019-11-29 13:55:25 +02:00
func WithCommand(args ...string) CreateOption {
2019-09-24 19:32:35 +02:00
return func(o *CreateOptions) {
// set command
2019-11-29 13:55:25 +02:00
o.Command = args
2019-09-24 19:32:35 +02:00
}
}
// WithEnv sets the created service environment
2019-09-24 19:32:35 +02:00
func WithEnv(env []string) CreateOption {
return func(o *CreateOptions) {
o.Env = env
}
}
2019-09-24 20:00:11 +02:00
// WithOutput sets the arg output
func WithOutput(out io.Writer) CreateOption {
return func(o *CreateOptions) {
o.Output = out
}
}
2019-11-29 13:35:00 +02:00
// ReadService returns services with the given name
func ReadService(service string) ReadOption {
return func(o *ReadOptions) {
o.Service = service
}
}
// WithVersion confifgures service version
2019-11-29 13:35:00 +02:00
func ReadVersion(version string) ReadOption {
return func(o *ReadOptions) {
o.Version = version
}
}
2019-11-29 13:35:00 +02:00
// ReadType returns services of the given type
func ReadType(t string) ReadOption {
return func(o *ReadOptions) {
o.Type = t
}
}