func heartbeat(s *service.Service) { go func() { for _ = range time.Tick(time.Duration(environment.Frequency()-1) * time.Second) { setServer(s) } }() }
func setServer(s *service.Service) { serviceurl, err := json.Marshal(environment.URL()) if err != nil { fmt.Fprintln(os.Stderr, err) } client := etcd.NewClient(Machines()) _, err = client.Set(serverPath(s), string(serviceurl), environment.Frequency()) if err != nil { fmt.Fprint(os.Stderr, err) } }
func refreshEtcdMachines() { go func() { for _ = range time.Tick(time.Duration(environment.Frequency()) * time.Second) { machines, err := environment.GetEnvValue("ETCD_MACHINES") if err != nil || machines == "" { if err != nil { fmt.Fprint(os.Stderr, err) } if machines == "" { fmt.Fprintf(os.Stderr, "ETCD_MACHINES not set.") } } else { etcdmachines = machines } } }() }