Example #1
0
// Build the configuration from Eureka server
func (provider *Eureka) buildConfiguration() (*types.Configuration, error) {
	var EurekaFuncMap = template.FuncMap{
		"replace":       replace,
		"tolower":       strings.ToLower,
		"getPort":       provider.getPort,
		"getProtocol":   provider.getProtocol,
		"getWeight":     provider.getWeight,
		"getInstanceID": provider.getInstanceID,
	}

	eureka.GetLogger().SetOutput(ioutil.Discard)

	client := eureka.NewClient([]string{
		provider.Endpoint,
	})

	applications, err := client.GetApplications()
	if err != nil {
		return nil, err
	}

	templateObjects := struct {
		Applications []eureka.Application
	}{
		applications.Applications,
	}

	configuration, err := provider.getConfiguration("templates/eureka.tmpl", EurekaFuncMap, templateObjects)
	if err != nil {
		log.Error(err)
	}
	return configuration, nil
}
Example #2
0
func GetEurekaClient() *EurekaClient {
	if eurekaClient != nil {
		return eurekaClient
	}
	var client *EurekaClient
	var err error
	conf := config.GetConfig()
	if conf.Eureka.Config.CertFile == "" || conf.Eureka.Config.KeyFile == "" {
		client = &EurekaClient{eureka.NewClient(conf.Eureka.Machines), conf.Instance.Name}
	} else {
		eurekaOriginalClient, err := eureka.NewTLSClient(
			conf.Eureka.Machines,
			conf.Eureka.Config.CertFile,
			conf.Eureka.Config.KeyFile,
			conf.Eureka.Config.CaCertFiles,
		)
		if err != nil {
			panic(err)
		}
		client = &EurekaClient{eurekaOriginalClient, conf.Instance.Name}
	}
	if err != nil {
		panic(err)
	}
	if conf.Eureka.Config.Consistency != "" {
		client.Config.Consistency = conf.Eureka.Config.Consistency
	}
	if conf.Eureka.Config.Timeout != 0 {
		client.Config.DialTimeout = time.Duration(conf.Eureka.Config.Timeout) * time.Second
	}
	eureka.SetLogger(logger.GetMinLog().GetLogger())
	return client
}