summaryrefslogtreecommitdiff
path: root/cmd
diff options
context:
space:
mode:
authorParamtamtam <[email protected]>2019-12-24 10:48:49 +0500
committerGitHub <[email protected]>2019-12-24 10:48:49 +0500
commitfbd2022729ab7ffe4eee8ba8b7357ba179e4d010 (patch)
treefa6b66b18259282b2efe00a41c445a3fa40aa701 /cmd
parent3f7d8bc007a4efdd48bb16253c2686006f0f9cda (diff)
parent75a817edcff22e721dcc3a7fa5590b866f630403 (diff)
Merge branch 'master' into master
Diffstat (limited to 'cmd')
-rw-r--r--cmd/rr/cmd/root.go4
-rw-r--r--cmd/rr/cmd/serve.go2
-rw-r--r--cmd/util/config.go23
3 files changed, 24 insertions, 5 deletions
diff --git a/cmd/rr/cmd/root.go b/cmd/rr/cmd/root.go
index d6929473..515e6419 100644
--- a/cmd/rr/cmd/root.go
+++ b/cmd/rr/cmd/root.go
@@ -33,6 +33,7 @@ import (
var (
cfgFile, workDir, logFormat string
override []string
+ mergeJson string
// Verbose enables verbosity mode (container specific).
Verbose bool
@@ -73,6 +74,7 @@ func init() {
CLI.PersistentFlags().StringVarP(&logFormat, "logFormat", "l", "color", "select log formatter (color, json, plain)")
CLI.PersistentFlags().StringVarP(&cfgFile, "config", "c", "", "config file (default is .rr.yaml)")
CLI.PersistentFlags().StringVarP(&workDir, "workDir", "w", "", "work directory")
+ CLI.PersistentFlags().StringVarP(&mergeJson, "jsonConfig", "j", "", "merge json configuration")
CLI.PersistentFlags().StringArrayVarP(
&override,
@@ -89,7 +91,7 @@ func init() {
configureLogger(logFormat)
- cfg, err := util.LoadConfig(cfgFile, []string{"."}, ".rr", override)
+ cfg, err := util.LoadConfig(cfgFile, []string{"."}, ".rr", override, mergeJson)
if err != nil {
Logger.Warnf("config: %s", err)
return
diff --git a/cmd/rr/cmd/serve.go b/cmd/rr/cmd/serve.go
index c754be46..1e8f53b2 100644
--- a/cmd/rr/cmd/serve.go
+++ b/cmd/rr/cmd/serve.go
@@ -36,7 +36,7 @@ func init() {
RunE: serveHandler,
})
- signal.Notify(stopSignal, os.Interrupt, os.Kill, syscall.SIGTERM, syscall.SIGINT)
+ signal.Notify(stopSignal, os.Interrupt, syscall.SIGTERM, syscall.SIGINT)
}
func serveHandler(cmd *cobra.Command, args []string) error {
diff --git a/cmd/util/config.go b/cmd/util/config.go
index 0a8d6005..08e01a89 100644
--- a/cmd/util/config.go
+++ b/cmd/util/config.go
@@ -1,6 +1,7 @@
package util
import (
+ "bytes"
"fmt"
"github.com/spf13/viper"
"github.com/spiral/roadrunner/service"
@@ -30,7 +31,7 @@ func (w *ConfigWrapper) Unmarshal(out interface{}) error {
}
// LoadConfig config and merge it's values with set of flags.
-func LoadConfig(cfgFile string, path []string, name string, flags []string) (*ConfigWrapper, error) {
+func LoadConfig(cfgFile string, path []string, name string, flags []string, jsonConfig string) (*ConfigWrapper, error) {
cfg := viper.New()
if cfgFile != "" {
@@ -68,14 +69,13 @@ func LoadConfig(cfgFile string, path []string, name string, flags []string) (*Co
// If a cfg file is found, read it in.
if err := cfg.ReadInConfig(); err != nil {
- if len(flags) == 0 {
+ if len(flags) == 0 && jsonConfig == "" {
return nil, err
}
}
// merge included configs
if include, ok := cfg.Get("include").([]interface{}); ok {
-
for _, file := range include {
filename, ok := file.(string)
if !ok {
@@ -117,6 +117,23 @@ func LoadConfig(cfgFile string, path []string, name string, flags []string) (*Co
}
}
+ if jsonConfig != "" {
+ jConfig := viper.New()
+ jConfig.AutomaticEnv()
+ jConfig.SetEnvPrefix("rr")
+ jConfig.SetEnvKeyReplacer(strings.NewReplacer(".", "_"))
+
+ jConfig.SetConfigType("json")
+ if err := jConfig.ReadConfig(bytes.NewBufferString(jsonConfig)); err != nil {
+ return nil, err
+ }
+
+ // merging
+ if err := cfg.MergeConfigMap(jConfig.AllSettings()); err != nil {
+ return nil, err
+ }
+ }
+
merged := viper.New()
// we have to copy all the merged values into new config in order normalize it (viper bug?)