示例#1
0
func (this *EtcdPeerManager) GetPeers() []string {
	out, err := GetEntries(this.client, this.Directory, this.Generator)
	if err != nil {
		log.Errorln(err)
	}
	return out
}
示例#2
0
func main() {

	if !flag.Parsed() {
		flag.Parse()
	}

	// 	etcd := os.Getenv("ETCD_ADDR")
	ip := os.Getenv("PUBLIC_HOSTIP")
	pport := os.Getenv("PUBLIC_PORT")

	cache := etcd_groupcache.New(fmt.Sprintf("http://%s:%s", ip, pport), nil, nil)
	peers := []string{fmt.Sprintf("http://%s:8080", ip), fmt.Sprintf("http://%s:8081", ip)}
	log.Infoln(peers)
	cache.Set(peers...)
	http.Handle("/_groupcache/", cache)

	var stringcache = groupcache.NewGroup("SlowDBCache", 64<<20, groupcache.GetterFunc(
		func(ctx groupcache.Context, key string, dest groupcache.Sink) error {
			log.Infoln(pport)
			dest.SetString(key + "heyo")
			return nil
		}))

	go func() {
		var data []byte
		key := "some key"
		err := stringcache.Get(nil, key, groupcache.AllocatingByteSliceSink(&data))
		if err != nil {
			log.Errorln(err)
		}
		log.Infoln(string(data))
	}()

	log.Infoln("Groupcache Listening 8080")
	if err := http.ListenAndServe(":"+*port, nil); err != nil {
		panic(err)
	}
}
示例#3
0
func (this *EtcdPeerManager) PeersChanged(stop chan bool) chan struct{} {
	receiver := make(chan *etcd.Response, 10)
	out := make(chan struct{}, 1)
	go func() {

		for {
			_, err := this.client.Watch(this.Directory, 0, true, receiver, stop)
			if err != nil {
				log.Errorln(err)
			}
			time.Sleep(20 * time.Second)
		}

		for {
			_, ok := <-receiver
			if !ok {
				return
			}
			out <- struct{}{}
		}

	}()
	return out
}
示例#4
0
func main() {

	flag.Parse()

	gitrepo, err := findgitroot(repo)
	if err != nil {
		log.Errorln(err)
		os.Exit(1)
		return
	}

	//get commit hash (short or not)
	cmd := func() *exec.Cmd {
		if short {
			return exec.Command("git", "--git-dir", gitrepo, "rev-parse", "--short", "HEAD")
		}

		return exec.Command("git", "--git-dir", gitrepo, "rev-parse", "HEAD")
	}()

	cmdOut, err := cmd.CombinedOutput()
	if err != nil {
		log.Errorln(err)
		os.Exit(1)
		return
	}

	// generate timestamp
	tsUnix := strconv.FormatInt(time.Now().Unix(), 10)
	var tsFmt string
	if tsformat != "" {
		tsFmt = time.Now().Format(tsformat)
	}

	// map of values for template
	vals := make(map[string]string)
	vals["githash"] = stripchars(string(cmdOut), "\r\n ")
	vals["ts"] = tsUnix
	vals["tsformat"] = tsFmt
	vals["pkg"] = pkg
	vals["versionstr"] = versionstr

	// create template
	tmpl, err := template.New("ver").Parse(Template)
	if err != nil {
		log.Errorln(err)
		os.Exit(1)
		return
	}

	// execute template
	var b bytes.Buffer
	if err = tmpl.Execute(&b, vals); err != nil {
		log.Errorln(err)
		os.Exit(1)
		return
	}

	//write file
	if err = ioutil.WriteFile(path, b.Bytes(), 0644); err != nil {
		log.Errorln(err)
		os.Exit(1)
	}
}