瀏覽代碼

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
 	}
 
-	// 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
 }
 

+ 3 - 3
config/config_test.go

@@ -479,7 +479,7 @@ func TestConfigCustomConfigOverrideSystemConfig(t *testing.T) {
 			c := New()
 			c.SystemPath = p1
 			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.SystemPath = ""
 		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.SystemPath = ""
 	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.
 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.
 	if e.Config.VeryVeryVerbose {
 		log.Verbose = true

+ 0 - 4
etcd/etcd_test.go

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