本文整理汇总了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
}
示例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
}
示例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.")
}
}
}
示例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)
}
}
}
示例5: unlock
func unlock(c *etcd.Client) {
for {
_, err := c.Set("lock", "unlock", 0)
if err == nil {
return
}
fmt.Println(err)
}
}
示例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))
}
}
示例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)
}
示例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
}
示例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)
}
}
示例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
}
}
}
示例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
}
示例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)
}
示例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
}
示例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
}
示例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))
}
}