فهرست منبع

chore(config): move Sanitize and Force check to boot process

Make Load function just load parameters. So etcd instance could
use Config struct to start service.
Yicheng Qin 12 سال پیش
والد
کامیت
b0ffb4fd10
4فایلهای تغییر یافته به همراه13 افزوده شده و 17 حذف شده
  1. 0 10
      config/config.go
  2. 3 3
      config/config_test.go
  3. 10 0
      etcd/etcd.go
  4. 0 4
      etcd/etcd_test.go

+ 0 - 10
config/config.go

@@ -142,16 +142,6 @@ func (c *Config) Load(arguments []string) error {
 		return err
 		return err
 	}
 	}
 
 
-	// Sanitize all the input fields.
-	if err := c.Sanitize(); err != nil {
-		return fmt.Errorf("sanitize: %v", err)
-	}
-
-	// Force remove server configuration if specified.
-	if c.Force {
-		c.Reset()
-	}
-
 	return nil
 	return nil
 }
 }
 
 

+ 3 - 3
config/config_test.go

@@ -479,7 +479,7 @@ func TestConfigCustomConfigOverrideSystemConfig(t *testing.T) {
 			c := New()
 			c := New()
 			c.SystemPath = p1
 			c.SystemPath = p1
 			assert.Nil(t, c.Load([]string{"-config", p2}), "")
 			assert.Nil(t, c.Load([]string{"-config", p2}), "")
-			assert.Equal(t, c.Addr, "http://127.0.0.1:6000", "")
+			assert.Equal(t, c.Addr, "127.0.0.1:6000", "")
 		})
 		})
 	})
 	})
 }
 }
@@ -494,7 +494,7 @@ func TestConfigEnvVarOverrideCustomConfig(t *testing.T) {
 		c := New()
 		c := New()
 		c.SystemPath = ""
 		c.SystemPath = ""
 		assert.Nil(t, c.Load([]string{"-config", path}), "")
 		assert.Nil(t, c.Load([]string{"-config", path}), "")
-		assert.Equal(t, c.Peer.Addr, "http://127.0.0.1:8000", "")
+		assert.Equal(t, c.Peer.Addr, "127.0.0.1:8000", "")
 	})
 	})
 }
 }
 
 
@@ -506,7 +506,7 @@ func TestConfigCLIArgsOverrideEnvVar(t *testing.T) {
 	c := New()
 	c := New()
 	c.SystemPath = ""
 	c.SystemPath = ""
 	assert.Nil(t, c.Load([]string{"-addr", "127.0.0.1:2000"}), "")
 	assert.Nil(t, c.Load([]string{"-addr", "127.0.0.1:2000"}), "")
-	assert.Equal(t, c.Addr, "http://127.0.0.1:2000", "")
+	assert.Equal(t, c.Addr, "127.0.0.1:2000", "")
 }
 }
 
 
 //--------------------------------------
 //--------------------------------------

+ 10 - 0
etcd/etcd.go

@@ -61,6 +61,16 @@ func New(c *config.Config) *Etcd {
 
 
 // Run the etcd instance.
 // Run the etcd instance.
 func (e *Etcd) Run() {
 func (e *Etcd) Run() {
+	// Sanitize all the input fields.
+	if err := e.Config.Sanitize(); err != nil {
+		log.Fatalf("failed sanitizing configuration: %v", err)
+	}
+
+	// Force remove server configuration if specified.
+	if e.Config.Force {
+		e.Config.Reset()
+	}
+
 	// Enable options.
 	// Enable options.
 	if e.Config.VeryVeryVerbose {
 	if e.Config.VeryVeryVerbose {
 		log.Verbose = true
 		log.Verbose = true

+ 0 - 4
etcd/etcd_test.go

@@ -34,10 +34,6 @@ func TestRunStop(t *testing.T) {
 	config.Addr = "localhost:0"
 	config.Addr = "localhost:0"
 	config.Peer.Addr = "localhost:0"
 	config.Peer.Addr = "localhost:0"
 
 
-	if err := config.Sanitize(); err != nil {
-		t.Fatal(err)
-	}
-
 	etcd := New(config)
 	etcd := New(config)
 	go etcd.Run()
 	go etcd.Run()
 	<-etcd.ReadyNotify()
 	<-etcd.ReadyNotify()