2019-09-24 18:32:35 +01:00
|
|
|
package runtime
|
|
|
|
|
2019-09-24 19:00:11 +01:00
|
|
|
import (
|
|
|
|
"io"
|
|
|
|
)
|
|
|
|
|
2019-11-02 13:25:10 +00:00
|
|
|
type Option func(o *Options)
|
|
|
|
|
|
|
|
// Options configure runtime
|
|
|
|
type Options struct {
|
|
|
|
// Notifier for updates
|
|
|
|
Notifier Notifier
|
|
|
|
}
|
|
|
|
|
|
|
|
// AutoUpdate enables micro auto-updates
|
|
|
|
func WithNotifier(n Notifier) Option {
|
|
|
|
return func(o *Options) {
|
|
|
|
o.Notifier = n
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-09-24 18:32:35 +01:00
|
|
|
type CreateOption func(o *CreateOptions)
|
|
|
|
|
2019-11-02 13:25:10 +00:00
|
|
|
// CreateOptions configure runtime services
|
2019-09-24 18:32:35 +01:00
|
|
|
type CreateOptions struct {
|
|
|
|
// command to execute including args
|
|
|
|
Command []string
|
|
|
|
// Environment to configure
|
|
|
|
Env []string
|
2019-09-24 19:00:11 +01:00
|
|
|
// Log output
|
|
|
|
Output io.Writer
|
2019-09-24 18:32:35 +01:00
|
|
|
}
|
|
|
|
|
2019-09-24 19:00:11 +01:00
|
|
|
// WithCommand specifies the command to execute
|
2019-09-24 18:32:35 +01:00
|
|
|
func WithCommand(c string, args ...string) CreateOption {
|
|
|
|
return func(o *CreateOptions) {
|
|
|
|
// set command
|
|
|
|
o.Command = []string{c}
|
|
|
|
// set args
|
|
|
|
o.Command = append(o.Command, args...)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-11-02 13:25:10 +00:00
|
|
|
// WithEnv sets the created service environment
|
2019-09-24 18:32:35 +01:00
|
|
|
func WithEnv(env []string) CreateOption {
|
|
|
|
return func(o *CreateOptions) {
|
|
|
|
o.Env = env
|
|
|
|
}
|
|
|
|
}
|
2019-09-24 19:00:11 +01:00
|
|
|
|
|
|
|
// WithOutput sets the arg output
|
|
|
|
func WithOutput(out io.Writer) CreateOption {
|
|
|
|
return func(o *CreateOptions) {
|
|
|
|
o.Output = out
|
|
|
|
}
|
|
|
|
}
|
2019-11-15 13:41:40 +00:00
|
|
|
|
2019-11-25 16:31:14 +00:00
|
|
|
type ReadOption func(o *ReadOptions)
|
2019-11-15 13:41:40 +00:00
|
|
|
|
2019-11-25 16:31:14 +00:00
|
|
|
// ReadOptions queries runtime services
|
|
|
|
type ReadOptions struct {
|
2019-11-15 13:41:40 +00:00
|
|
|
// Version queries services with given version
|
|
|
|
Version string
|
|
|
|
}
|
|
|
|
|
|
|
|
// WithVersion confifgures service version
|
2019-11-25 16:31:14 +00:00
|
|
|
func WithVersion(version string) ReadOption {
|
|
|
|
return func(o *ReadOptions) {
|
2019-11-15 13:41:40 +00:00
|
|
|
o.Version = version
|
|
|
|
}
|
|
|
|
}
|