* Add String to Runtime interface

* Setup Dynamic Runtime Configuration
This commit is contained in:
ben-toogood
2020-02-05 13:59:35 +00:00
committed by GitHub
parent 4333f00a43
commit bf747a86f4
7 changed files with 50 additions and 1 deletions

View File

@@ -40,6 +40,11 @@ import (
rmem "github.com/micro/go-micro/v2/registry/memory"
regSrv "github.com/micro/go-micro/v2/registry/service"
// runtimes
kRuntime "github.com/micro/go-micro/v2/runtime/kubernetes"
lRuntime "github.com/micro/go-micro/v2/runtime/local"
srvRuntime "github.com/micro/go-micro/v2/runtime/service"
// selectors
"github.com/micro/go-micro/v2/client/selector/dns"
"github.com/micro/go-micro/v2/client/selector/router"
@@ -188,6 +193,12 @@ var (
EnvVars: []string{"MICRO_RUNTIME"},
Value: "local",
},
&cli.StringFlag{
Name: "runtime_source",
Usage: "Runtime source for building and running services e.g github.com/micro/service",
EnvVars: []string{"MICRO_RUNTIME_SOURCE"},
Value: "github.com/micro/services",
},
&cli.StringFlag{
Name: "selector",
EnvVars: []string{"MICRO_SELECTOR"},
@@ -281,7 +292,9 @@ var (
}
DefaultRuntimes = map[string]func(...runtime.Option) runtime.Runtime{
"local": runtime.NewRuntime,
"local": lRuntime.NewRuntime,
"service": srvRuntime.NewRuntime,
"kubernetes": kRuntime.NewRuntime,
}
DefaultStores = map[string]func(...store.Option) store.Store{
@@ -580,6 +593,12 @@ func (c *cmd) Before(ctx *cli.Context) error {
}
}
if len(ctx.String("runtime_source")) > 0 {
if err := (*c.opts.Runtime).Init(runtime.WithSource(ctx.String("runtime_source"))); err != nil {
log.Fatalf("Error configuring runtime: %v", err)
}
}
// client opts
if r := ctx.Int("client_retries"); r >= 0 {
clientOpts = append(clientOpts, client.Retries(r))