Пример #1
0
func TestConsulNodeConfigDefaults(t *testing.T) {
	cfg := &ConsulNodeConfig{}
	err := cfg.Normalize()
	if err != nil {
		panic(err)
	}

	assert.Equal(t, cfg.ListenPort, vega.DefaultPort)

	ip, err := vega.GetPrivateIP()
	if err != nil {
		panic(err)
	}

	assert.Equal(t, cfg.AdvertiseAddr, ip.String())
	assert.Equal(t, cfg.DataPath, DefaultPath)
}
Пример #2
0
func (cn *ConsulNodeConfig) Normalize() error {
	if cn.ListenPort == 0 {
		cn.ListenPort = vega.DefaultPort
	}

	if cn.AdvertiseAddr == "" {
		ip, err := vega.GetPrivateIP()
		if err != nil {
			cn.AdvertiseAddr = "127.0.0.1"
		} else {
			cn.AdvertiseAddr = ip.String()
		}
	}

	if cn.DataPath == "" {
		cn.DataPath = DefaultPath
	}

	if cn.RoutingPrefix == "" {
		cn.RoutingPrefix = DefaultRoutingPrefix
	}

	return nil
}