当前位置: 首页>>代码示例>>Golang>>正文


Golang Client.Set方法代码示例

本文整理汇总了Golang中github.com/coreos/go-etcd/etcd.Client.Set方法的典型用法代码示例。如果您正苦于以下问题:Golang Client.Set方法的具体用法?Golang Client.Set怎么用?Golang Client.Set使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在github.com/coreos/go-etcd/etcd.Client的用法示例。


在下文中一共展示了Client.Set方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: addDNS

func addDNS(record string, service *kapi.Service, etcdClient *etcd.Client) error {
	// if PortalIP is not set, a DNS entry should not be created
	if !kapi.IsServiceIPSet(service) {
		log.Printf("Skipping dns record for headless service: %s\n", service.Name)
		return nil
	}

	for i := range service.Spec.Ports {
		svc := skymsg.Service{
			Host:     service.Spec.PortalIP,
			Port:     service.Spec.Ports[i].Port,
			Priority: 10,
			Weight:   10,
			Ttl:      30,
		}
		b, err := json.Marshal(svc)
		if err != nil {
			return err
		}
		// Set with no TTL, and hope that kubernetes events are accurate.

		log.Printf("Setting DNS record: %v -> %s:%d\n", record, service.Spec.PortalIP, service.Spec.Ports[i].Port)
		_, err = etcdClient.Set(skymsg.Path(record), string(b), uint64(0))
		if err != nil {
			return err
		}
	}
	return nil
}
开发者ID:SivagnanamCiena,项目名称:calico-kubernetes,代码行数:29,代码来源:kube2sky.go

示例2: SetKey

// SetKey is used to log key value pairs to stdout/etcd so that dray can pass
// them down to subsequent images as needed. By default keys are logged to
// stdout as ----BEGIN PANAMAX DATA----\nkey=value\n----END PANAMAX DATA----
// tags. If LOG_TO env var is set to etcd, then keys are logged to etcd.
// The etcd api is set using ETCD_API env variable.
func SetKey(key string, value string) error {
	logTo := os.Getenv("LOG_TO")
	if logTo == "" {
		logTo = "stdout"
	}
	logTo = strings.ToLower(logTo)

	if logTo == "etcd" {
		log.Info("Logging Keys to etcd...")
		var ec *etcd.Client
		eIP := os.Getenv("ETCD_API")
		if eIP == "" {
			eIP = "172.17.42.1:4001"
		}
		eIP = fmt.Sprintf("http://%s", eIP)
		ms := []string{eIP}
		ec = etcd.NewClient(ms)
		_, e := ec.Set(key, value, 0)

		if e != nil {
			return e
		}
	} else {
		fmt.Printf("\n----BEGIN PANAMAX DATA----\n%s=%s\n----END PANAMAX DATA----\n", key, value)
	}
	return nil
}
开发者ID:rupakg,项目名称:kube-cluster-deploy,代码行数:32,代码来源:keys.go

示例3: dispatchCommand

func dispatchCommand(c *cli.Context, client *etcd.Client, cmd *command.Command) {
	targets := c.StringSlice("target")
	if targets == nil || len(targets) == 0 {
		log.Warningln("no target set! try to send command to all registered host.")
		targets = fetchHosts(c, client)
	}
	if targets == nil {
		log.Fatalln("no target to send command.")
	} else {
		log.Infoln("send command to: ", targets)
	}
	for _, target := range targets {
		key := fmt.Sprintf("/beacon/commands/single/%s/%s/",
			target, cmd.Id)
		if c.GlobalString("prefix") != "" {
			key = fmt.Sprintf("/%s%s", strings.Trim(c.GlobalString("prefix"), "/"), key)
		}

		if _, err := client.Set(key, cmd.Marshal(), 0); err != nil {
			log.WithFields(log.Fields{
				"error": err.Error(),
			}).Fatalln("send command failed.")
		}
	}
}
开发者ID:jmptrader,项目名称:beacon,代码行数:25,代码来源:utils.go

示例4: SetEtcd

// SetEtcd sets an array of values into a test etcd instance.
func SetEtcd(t *testing.T, keys []string, values []string, c *etcd.Client) {
	for i, key := range keys {
		_, err := c.Set(key, values[i], 0)
		if err != nil {
			t.Fatal(err)
		}
	}
}
开发者ID:ericcapricorn,项目名称:deis,代码行数:9,代码来源:etcdutils.go

示例5: unlock

func unlock(c *etcd.Client) {
	for {
		_, err := c.Set("lock", "unlock", 0)
		if err == nil {
			return
		}
		fmt.Println(err)
	}
}
开发者ID:sunatthegilddotcom,项目名称:etcd,代码行数:9,代码来源:mutex.go

示例6: beat

func beat(client *etcd.Client, ip string, conf *config.Config) {
	for {
		if _, err := client.Set(conf.Etcd_dir+"/"+ip, conf.Agent_id, uint64(conf.Heartbeat_interval*2)); err != nil {
			log.Fatal(err)
		}
		fmt.Printf("%v beat sent.\n", time.Now())
		time.Sleep(time.Second * time.Duration(conf.Heartbeat_interval))
	}
}
开发者ID:wonderflow,项目名称:cloudagent,代码行数:9,代码来源:etcd.go

示例7: AnnounceSite

func AnnounceSite(id string, site Site, client *etcd.Client) {
	key := fmt.Sprintf("/nginx/sites/%s", id)
	value := FormatSite(site)

	client.Set(key, value, 60)
	log.Println("announcing", id, "as", value)
	time.Sleep(30 * time.Second)
	go AnnounceSite(id, site, client)
}
开发者ID:lrolaz,项目名称:nginx-confd,代码行数:9,代码来源:app.go

示例8: setAll

func setAll(c *etcd.Client, dir string, data map[string]string) error {
	for name, item := range data {
		_, err := c.Set(dir+name, item, 0)
		if err != nil {
			return err
		}
	}

	return nil
}
开发者ID:hafizh,项目名称:skipper,代码行数:10,代码来源:etcd_test.go

示例9: TrackMyStats

// TrackStats is going to pull all pertinent system stats and update our state in etcd
func TrackMyStats(cli *etcd.Client, myid string, stats []string) {
	for {
		cli.Set(path.Join("fiddler/servers", myid), "present", 60)

		for _, stat := range stats {
			// Get the value for the stat and set cli key for the value
			stat := NewStat(stat)
			stat.write(myid, cli)
		}

		time.Sleep(3 * time.Second)
	}
}
开发者ID:hayesgm,项目名称:fiddler,代码行数:14,代码来源:tracker.go

示例10: Heartbeat

// heartbeat to etcd cluster until stop
func Heartbeat(client *etcd.Client, name string, taskID uint64, interval time.Duration, stop chan struct{}) error {
	for {
		_, err := client.Set(TaskHealthyPath(name, taskID), "health", computeTTL(interval))
		if err != nil {
			return err
		}
		select {
		case <-time.After(interval):
		case <-stop:
			return nil
		}
	}
}
开发者ID:yangjunpro,项目名称:taskgraph,代码行数:14,代码来源:healthy.go

示例11: Create

// Create Etcd directory structure from a map, slice or struct.
func Create(client *etcd.Client, path string, val reflect.Value) error {
	// fmt.Printf("# %s : %s : %s\n", path, val.Kind(), val.Type())

	switch val.Kind() {
	case reflect.Ptr:
		orig := val.Elem()
		if !orig.IsValid() {
			return nil
		}
		if err := Create(client, path, orig); err != nil {
			return err
		}
	case reflect.Interface:
		orig := val.Elem()
		if err := Create(client, path, orig); err != nil {
			return err
		}
	case reflect.Struct:
		for i := 0; i < val.NumField(); i++ {
			t := val.Type().Field(i)
			k := t.Tag.Get("etcd")
			if err := Create(client, path+"/"+k, val.Field(i)); err != nil {
				return err
			}
		}
	case reflect.Map:
		for _, k := range val.MapKeys() {
			v := val.MapIndex(k)
			if err := Create(client, path+"/"+k.String(), v); err != nil {
				return err
			}
		}
	case reflect.Slice:
		for i := 0; i < val.Len(); i++ {
			Create(client, fmt.Sprintf("%s/%d", path, i), val.Index(i))
		}
	case reflect.String:
		if _, err := client.Set(path, val.String(), 0); err != nil {
			return err
		}
	case reflect.Bool, reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64,
		reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64, reflect.Float32, reflect.Float64:
		if _, err := client.Set(path, fmt.Sprintf("%v", val.Interface()), 0); err != nil {
			return err
		}
	default:
		return fmt.Errorf("unsupported type: %s for path: %s", val.Kind(), path)
	}

	return nil
}
开发者ID:smithjm,项目名称:etcd-export,代码行数:52,代码来源:etcdmap.go

示例12: etcd_SetData

func etcd_SetData(key string, value string) {
	info := config.GetServerInfo()
	log.Printf("info : %s\n", info.AccessString)

	var client *etcd.Client = nil
	client = etcd.NewClient(info.AccessString)

	_, err := client.Set(key, value, 0)

	if err != nil {
		log.Fatal(err)
		log.Printf("etcd_Setdata ERROR")
	}

	log.Printf("Current Set information: %s\n", value)
}
开发者ID:pegasuskim,项目名称:moniter-etcd,代码行数:16,代码来源:etcdWathing.go

示例13: TryOccupyTask

func TryOccupyTask(client *etcd.Client, name string, taskID uint64, connection string) (bool, error) {
	_, err := client.Create(TaskHealthyPath(name, taskID), "health", 3)
	if err != nil {
		if strings.Contains(err.Error(), "Key already exists") {
			return false, nil
		}
		return false, err
	}
	idStr := strconv.FormatUint(taskID, 10)
	client.Delete(FreeTaskPath(name, idStr), false)
	_, err = client.Set(TaskMasterPath(name, taskID), connection, 0)
	if err != nil {
		return false, err
	}
	return true, nil
}
开发者ID:yangjunpro,项目名称:taskgraph,代码行数:16,代码来源:task.go

示例14: addDNS

func addDNS(record string, service *kapi.Service, etcdClient *etcd.Client) error {
	svc := skymsg.Service{
		Host:     service.Spec.PortalIP,
		Port:     service.Spec.Port,
		Priority: 10,
		Weight:   10,
		Ttl:      30,
	}
	b, err := json.Marshal(svc)
	if err != nil {
		return err
	}
	// Set with no TTL, and hope that kubernetes events are accurate.

	log.Printf("Setting dns record: %v -> %s:%d\n", record, service.Spec.PortalIP, service.Spec.Port)
	_, err = etcdClient.Set(skymsg.Path(record), string(b), uint64(0))
	return err
}
开发者ID:vrosnet,项目名称:kubernetes,代码行数:18,代码来源:kube2sky.go

示例15: setCommandFunc

// setCommandFunc executes the "set" command.
func setCommandFunc(cmd *cobra.Command, args []string, client *etcd.Client) (*etcd.Response, error) {
	if len(args) == 0 {
		return nil, errors.New("Key required")
	}
	key := args[0]
	value, err := argOrStdin(args, os.Stdin, 1)
	if err != nil {
		return nil, errors.New("Value required")
	}

	ttl := ttlFlag
	prevValue := swapWithValueFlag
	prevIndex := swapWithIndexFlag

	if prevValue == "" && prevIndex == 0 {
		return client.Set(key, value, uint64(ttl))
	} else {
		return client.CompareAndSwap(key, value, uint64(ttl), prevValue, uint64(prevIndex))
	}
}
开发者ID:joshi4,项目名称:etcdctl,代码行数:21,代码来源:set_command.go


注:本文中的github.com/coreos/go-etcd/etcd.Client.Set方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。