예제 #1
0
func CreateEurekaClientByYaml(fileName string) *Client {
	file, _ := os.Getwd()
	fmt.Println("current path:", file)
	if fileName == "" {
		fileName = "application.yml"
	}

	cfg := file + "/" + fileName //"/application.yml"

	c := config.EurekaConfig{
		Eureka: config.Eureka{
			Client:   config.NewEurekaClientConfig(),
			Instance: config.NewEurekaInstanceConfig(),
		},
	}

	if exists(cfg) {

		data, err := ReadFile(cfg)
		err = yaml.Unmarshal([]byte(data), &c)
		if err != nil {
			fmt.Println("error: %v", err)
		}
	} else {
		fmt.Println("error: file %s not exists.", cfg)
	}

	ins := CreateInstanceInfo(c)
	client := CreateEurekaClient(c.Eureka.Client)
	client.InstanceInfo = ins
	return client
}
예제 #2
0
func main2() {

	file, _ := os.Getwd()
	fmt.Println("current path:", file)

	cfg := file + "/application.yml"
	data, err := ReadFile(cfg)
	c := config.EurekaConfig{
		Eureka: config.Eureka{
			Client:   config.NewEurekaClientConfig(),
			Instance: config.NewEurekaInstanceConfig(),
		},
	}
	err = yaml.Unmarshal([]byte(data), &c)
	if err != nil {
		log.Fatalf("error: %v", err)
	}
	fmt.Println(c.Eureka.Client.ServiceUrl)
	fmt.Println(c.Eureka.Instance.LeaseRenewalIntervalInSeconds)
	fmt.Println(c.Application.Name)
	fmt.Println(c.Application.Port)
	fmt.Println(c.Eureka.Instance.Appname)
	//	c.Eureka.Client.ServiceUrl = make(map[string]string)
	//	c.Eureka.Client.ServiceUrl["ali-hz-1"] = "http://127.0.0.1:8761/eureka"
	d, err := yaml.Marshal(&c)
	if err != nil {
		log.Fatalf("error: %v", err)
	}
	fmt.Printf("--- t dump:\n%s\n\n", string(d))
}