Esempio n. 1
0
func (v *Config) Build() (*core.Config, error) {
	config := new(core.Config)

	if v.LogConfig != nil {
		config.Log = v.LogConfig.Build()
	}

	if v.Transport != nil {
		ts, err := v.Transport.Build()
		if err != nil {
			return nil, err
		}
		config.Transport = ts
	}

	if v.RouterConfig != nil {
		routerConfig, err := v.RouterConfig.Build()
		if err != nil {
			return nil, err
		}
		config.App = append(config.App, serial.ToTypedMessage(routerConfig))
	}

	if v.DNSConfig != nil {
		config.App = append(config.App, serial.ToTypedMessage(v.DNSConfig.Build()))
	}

	if v.InboundConfig == nil {
		return nil, errors.New("No inbound config specified.")
	}

	if v.InboundConfig.Port == 0 && v.Port > 0 {
		v.InboundConfig.Port = v.Port
	}

	ic, err := v.InboundConfig.Build()
	if err != nil {
		return nil, err
	}
	config.Inbound = append(config.Inbound, ic)

	for _, rawInboundConfig := range v.InboundDetours {
		ic, err := rawInboundConfig.Build()
		if err != nil {
			return nil, err
		}
		config.Inbound = append(config.Inbound, ic)
	}

	oc, err := v.OutboundConfig.Build()
	if err != nil {
		return nil, err
	}
	config.Outbound = append(config.Outbound, oc)

	for _, rawOutboundConfig := range v.OutboundDetours {
		oc, err := rawOutboundConfig.Build()
		if err != nil {
			return nil, err
		}
		config.Outbound = append(config.Outbound, oc)
	}

	return config, nil
}
Esempio n. 2
0
func (this *Config) Build() (*core.Config, error) {
	config := new(core.Config)

	if this.LogConfig != nil {
		config.Log = this.LogConfig.Build()
	}

	if this.Transport != nil {
		ts, err := this.Transport.Build()
		if err != nil {
			return nil, err
		}
		config.Transport = ts
	}

	if this.RouterConfig != nil {
		routerConfig, err := this.RouterConfig.Build()
		if err != nil {
			return nil, err
		}
		config.App = append(config.App, loader.NewTypedSettings(routerConfig))
	}

	if this.DNSConfig != nil {
		config.App = append(config.App, loader.NewTypedSettings(this.DNSConfig.Build()))
	}

	if this.InboundConfig == nil {
		return nil, errors.New("No inbound config specified.")
	}

	if this.InboundConfig.Port == 0 && this.Port > 0 {
		this.InboundConfig.Port = this.Port
	}

	ic, err := this.InboundConfig.Build()
	if err != nil {
		return nil, err
	}
	config.Inbound = append(config.Inbound, ic)

	for _, rawInboundConfig := range this.InboundDetours {
		ic, err := rawInboundConfig.Build()
		if err != nil {
			return nil, err
		}
		config.Inbound = append(config.Inbound, ic)
	}

	oc, err := this.OutboundConfig.Build()
	if err != nil {
		return nil, err
	}
	config.Outbound = append(config.Outbound, oc)

	for _, rawOutboundConfig := range this.OutboundDetours {
		oc, err := rawOutboundConfig.Build()
		if err != nil {
			return nil, err
		}
		config.Outbound = append(config.Outbound, oc)
	}

	return config, nil
}