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


Golang etcd.NewClient函数代码示例

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


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

示例1: TestConnHashTestSuite

func TestConnHashTestSuite(t *testing.T) {
	if testing.Short() {
		t.Skip("Skipping zk shard test in short mode.")
	}
	//launch zk
	sl := test.NewServiceLauncher()
	etcdOriPort, stopEtcd, err := sl.Start(test.Etcd)
	assert.NoError(t, err)
	s := new(ConnHashTestSuite)
	s.etcdOriPort = etcdOriPort
	s.etcdPort = 3333 // used for port forward
	s.forwarder = portForwarder(
		fmt.Sprintf(":%d", s.etcdPort), fmt.Sprintf(":%d", s.etcdOriPort))

	s.stopForward, err = s.forwarder()
	assert.NoError(t, err, "no error")

	// non-forward etcdCli
	etcdCli = etcd.NewClient([]string{fmt.Sprintf("http://localhost:%d", etcdOriPort)})
	// forwardable etcdCli
	etcdForwdCli = etcd.NewClient([]string{fmt.Sprintf("http://localhost:%d", s.etcdPort)})
	suite.Run(t, s)

	// clean up the forwarding
	s.stopForward <- struct{}{}
	etcdCli.Close()
	etcdForwdCli.Close()
	assert.NoError(s.T(), stopEtcd())
}
开发者ID:csigo,项目名称:shard,代码行数:29,代码来源:shard_test.go

示例2: main

func main() {

	// Setup
	servers := []string{"http://localhost:4001"}
	log.Printf("Creating etcd client pointing to %v", servers)
	etcdClient := etcd.NewClient(servers)
	machineList := []string{"machine"}

	reg := registry.MakeEtcdRegistry(etcdClient, machineList)

	apiserver := apiserver.New(map[string]apiserver.RESTStorage{
		"pods": registry.MakePodRegistryStorage(reg, &client.FakeContainerInfo{}, registry.MakeRoundRobinScheduler(machineList)),
		"replicationControllers": registry.MakeControllerRegistryStorage(reg),
	}, "/api/v1beta1")
	server := httptest.NewServer(apiserver)

	controllerManager := registry.MakeReplicationManager(etcd.NewClient(servers),
		client.Client{
			Host: server.URL,
		})

	go controllerManager.Synchronize()
	go controllerManager.WatchControllers()

	// Ok. we're good to go.
	log.Printf("API Server started on %s", server.URL)
	// Wait for the synchronization threads to come up.
	time.Sleep(time.Second * 10)

	kubeClient := client.Client{
		Host: server.URL,
	}
	data, err := ioutil.ReadFile("api/examples/controller.json")
	if err != nil {
		log.Fatalf("Unexpected error: %#v", err)
	}
	var controllerRequest api.ReplicationController
	if err = json.Unmarshal(data, &controllerRequest); err != nil {
		log.Fatalf("Unexpected error: %#v", err)
	}

	if _, err = kubeClient.CreateReplicationController(controllerRequest); err != nil {
		log.Fatalf("Unexpected error: %#v", err)
	}
	// Give the controllers some time to actually create the pods
	time.Sleep(time.Second * 10)

	// Validate that they're truly up.
	pods, err := kubeClient.ListPods(nil)
	if err != nil || len(pods.Items) != 2 {
		log.Fatal("FAILED")
	}
	log.Printf("OK")
}
开发者ID:happywky,项目名称:kubernetes,代码行数:54,代码来源:integration.go

示例3: Init

func (r *Reconfigurator) Init(host, port string) error {
	r.configs = make(map[string]*Config)

	if host == "" {
		return errors.New("Invalid host: " + host)
	} else {
		r.etcdHost = host
	}

	if port == "" {
		return errors.New("Invalid port: " + port)
	} else {
		r.etcdPort = port
	}

	// make sure host has expected prefix
	etcdHost := host
	if !strings.HasPrefix(host, "http://") {
		etcdHost = "http://" + host
	}

	client := etcd.NewClient([]string{etcdHost + ":" + port})

	if client == nil {
		return errors.New("Unable to created ETCD client")
	} else {
		r.client = client
		return nil
	}
}
开发者ID:whiteops-dot-com,项目名称:dynconfig,代码行数:30,代码来源:dynconfig.go

示例4: main

func main() {
	host := getopt("HOST", "127.0.0.1")

	etcdPort := getopt("ETCD_PORT", "4001")
	etcdPath := getopt("ETCD_PATH", "/deis/cache")

	externalPort := getopt("EXTERNAL_PORT", "6379")

	client := etcd.NewClient([]string{"http://" + host + ":" + etcdPort})

	var maxmemory string
	result, err := client.Get("/deis/cache/maxmemory", false, false)
	if err != nil {
		if e, ok := err.(*etcd.EtcdError); ok && e.ErrorCode == ectdKeyNotFound {
			maxmemory = defaultMemory
		} else {
			log.Fatalln(err)
		}
	} else {
		maxmemory = result.Node.Key
	}
	replaceMaxmemoryInConfig(maxmemory)

	go launchRedis()

	go publishService(client, host, etcdPath, externalPort, uint64(ttl.Seconds()))

	// Wait for terminating signal
	exitChan := make(chan os.Signal, 2)
	signal.Notify(exitChan, syscall.SIGTERM, syscall.SIGINT)
	<-exitChan
}
开发者ID:gpxl,项目名称:deis,代码行数:32,代码来源:main.go

示例5: main

// Main method.
func main() {
	conf := config.New()

	help, version := false, false
	flag.BoolVar(&help, "help", false, "Prints command line options and exit.")
	flag.BoolVar(&version, "version", false, "Prints the etcdsh version and exit.")
	flag.StringVar(&conf.Machine, "machine", conf.Machine, "Connect to this etcd server.")
	flag.StringVar(&conf.PS1, "ps1", conf.PS1, "First prompt format")
	flag.StringVar(&conf.PS2, "ps2", conf.PS2, "Second prompt format")
	flag.BoolVar(&conf.Colors, "colors", conf.Colors, "Use colors in display.")
	flag.Parse()

	if help {
		printHelp()
		os.Exit(0)
	}
	if version {
		printVersion()
		os.Exit(0)
	}

	fmt.Printf("Connecting to %s\n", conf.Machine)
	client := etcd.NewClient([]string{conf.Machine})

	controller := handlers.NewController(conf, client, os.Stdout, os.Stderr, os.Stdin)
	controller.Add(handlers.NewLsHandler(controller))
	controller.Add(handlers.NewSetHandler(controller))
	controller.Add(handlers.NewHelpHandler(controller))
	controller.Add(handlers.NewCdHandler(controller))
	controller.Add(handlers.NewGetHandler(controller))
	os.Exit(controller.Start())
}
开发者ID:headzoo,项目名称:etcdsh,代码行数:33,代码来源:main.go

示例6: main

func main() {
	name := os.Getenv("VIRTUAL_HOST")
	site := NewSite(name)
	client := etcd.NewClient([]string{os.Getenv("ETCD_URL")})
	go AnnounceSite(name, site, client)
	select {}
}
开发者ID:lrolaz,项目名称:nginx-confd,代码行数:7,代码来源:app.go

示例7: NewClientEtcd

func NewClientEtcd(uqProtocol string, etcdAddr []string, etcdKey string) (*Client, error) {
	client := new(Client)
	if len(etcdAddr) > 0 {
		etcdClient := etcd.NewClient(etcdAddr)
		var uqConn Conn
		var err error
		if uqProtocol == ProtoRedis {
			uqConn, err = newConnRedisEtcd(etcdClient, etcdKey)
			if err != nil {
				return nil, err
			}
		} else if uqProtocol == ProtoMc {
			uqConn, err = newConnMcEtcd(etcdClient, etcdKey)
			if err != nil {
				return nil, err
			}
		} else if uqProtocol == ProtoHttp {
			uqConn, err = newConnHttpEtcd(etcdClient, etcdKey)
			if err != nil {
				return nil, err
			}
		}
		client.uqConn = uqConn
	} else {
		return nil, errors.New("etcd address nil")
	}
	return client, nil
}
开发者ID:jmptrader,项目名称:libuq,代码行数:28,代码来源:libuq.go

示例8: newKubernetesMaster

func newKubernetesMaster(scheduler *scheduler.KubernetesScheduler, c *master.Config) *kubernetesMaster {
	var m *kubernetesMaster

	if len(c.EtcdServers) > 0 {
		etcdClient := etcd.NewClient(c.EtcdServers)
		minionRegistry := registry.MakeMinionRegistry(c.Minions)
		m = &kubernetesMaster{
			podRegistry:        scheduler,
			controllerRegistry: registry.MakeEtcdRegistry(etcdClient, minionRegistry),
			serviceRegistry:    registry.MakeEtcdRegistry(etcdClient, minionRegistry),
			minionRegistry:     minionRegistry,
			client:             c.Client,
		}
		m.init(scheduler, c.Cloud, c.PodInfoGetter)
	} else {
		m = &kubernetesMaster{
			podRegistry:        scheduler,
			controllerRegistry: registry.MakeMemoryRegistry(),
			serviceRegistry:    registry.MakeMemoryRegistry(),
			minionRegistry:     registry.MakeMinionRegistry(c.Minions),
			client:             c.Client,
		}
		m.init(scheduler, c.Cloud, c.PodInfoGetter)
	}
	return m
}
开发者ID:nqn,项目名称:kubernetes-mesos,代码行数:26,代码来源:main.go

示例9: RunKubelet

// Starts background goroutines. If file, manifest_url, or address are empty,
// they are not watched. Never returns.
func (kl *Kubelet) RunKubelet(file, manifest_url, etcd_servers, address string, port uint) {
	fileChannel := make(chan api.ContainerManifest)
	etcdChannel := make(chan []api.ContainerManifest)
	httpChannel := make(chan api.ContainerManifest)
	serverChannel := make(chan api.ContainerManifest)

	go util.Forever(func() { kl.WatchFile(file, fileChannel) }, 20*time.Second)
	if manifest_url != "" {
		go util.Forever(func() { kl.WatchHTTP(manifest_url, httpChannel) }, 20*time.Second)
	}
	if etcd_servers != "" {
		servers := []string{etcd_servers}
		log.Printf("Creating etcd client pointing to %v", servers)
		kl.Client = etcd.NewClient(servers)
		go util.Forever(func() { kl.SyncAndSetupEtcdWatch(etcdChannel) }, 20*time.Second)
	}
	if address != "" {
		log.Printf("Starting to listen on %s:%d", address, port)
		handler := KubeletServer{
			Kubelet:       kl,
			UpdateChannel: serverChannel,
		}
		s := &http.Server{
			// TODO: This is broken if address is an ipv6 address.
			Addr:           fmt.Sprintf("%s:%d", address, port),
			Handler:        &handler,
			ReadTimeout:    10 * time.Second,
			WriteTimeout:   10 * time.Second,
			MaxHeaderBytes: 1 << 20,
		}
		go util.Forever(func() { s.ListenAndServe() }, 0)
	}
	kl.RunSyncLoop(etcdChannel, fileChannel, serverChannel, httpChannel, kl)
}
开发者ID:Jingzhe88,项目名称:kubernetes,代码行数:36,代码来源:kubelet.go

示例10: EtcdClient

// EtcdClient creates an etcd client based on the provided config.
func EtcdClient(etcdClientInfo configapi.EtcdConnectionInfo) (*etcdclient.Client, error) {
	tlsConfig, err := client.TLSConfigFor(&client.Config{
		TLSClientConfig: client.TLSClientConfig{
			CertFile: etcdClientInfo.ClientCert.CertFile,
			KeyFile:  etcdClientInfo.ClientCert.KeyFile,
			CAFile:   etcdClientInfo.CA,
		},
	})
	if err != nil {
		return nil, err
	}

	transport := knet.SetTransportDefaults(&http.Transport{
		TLSClientConfig: tlsConfig,
		Dial: (&net.Dialer{
			// default from http.DefaultTransport
			Timeout: 30 * time.Second,
			// Lower the keep alive for connections.
			KeepAlive: 1 * time.Second,
		}).Dial,
		// Because watches are very bursty, defends against long delays in watch reconnections.
		MaxIdleConnsPerHost: 500,
	})

	etcdClient := etcdclient.NewClient(etcdClientInfo.URLs)
	etcdClient.SetTransport(transport)
	etcdClient.CheckRetry = NeverRetryOnFailure
	return etcdClient, nil
}
开发者ID:richm,项目名称:origin,代码行数:30,代码来源:etcd.go

示例11: Example_nestedStruct

// ExampleNestedStruct creates a Etcd directory using a nested Go struct and then gets the directory as JSON.
func Example_nestedStruct() {
	verbose := flag.Bool("verbose", false, "Verbose")
	node := flag.String("node", "", "Etcd node")
	port := flag.String("port", "", "Etcd port")
	flag.Parse()

	// Define nested structure.
	g := Group{
		Name: "staff",
		Users: []User{
			User{
				Name:      "jdoe",
				Age:       25,
				Male:      true,
				FirstName: "John",
				LastName:  "Doe",
			},
			User{
				Name:      "lnemoy",
				Age:       62,
				Male:      true,
				FirstName: "Leonard",
				LastName:  "Nimoy",
			},
		},
	}

	// Connect to Etcd.
	conn := getEnv()
	if node == nil && port == nil {
		conn = []string{fmt.Sprintf("http://%v:%v", *node, *port)}
	}

	if *verbose {
		log.Printf("Connecting to: %s", conn)
	}
	client := etcd.NewClient(conn)

	// Create directory structure based on struct.
	err := etcdmap.Create(client, "/example", reflect.ValueOf(g))
	if err != nil {
		log.Fatal(err.Error())
	}

	// Get directory structure from Etcd.
	res, err := client.Get("/example", true, true)
	if err != nil {
		log.Fatal(err.Error())
	}

	j, err2 := etcdmap.JSON(res.Node)
	if err2 != nil {
		log.Fatal(err2.Error())
	}

	fmt.Println(string(j))

	// Output:
	//{"id":"staff","users":{"0":{"age":"25","first_name":"John","id":"jdoe","last_name":"Doe","male":"true"},"1":{"age":"62","first_name":"Leonard","id":"lnemoy","last_name":"Nimoy","male":"true"}}}
}
开发者ID:smithjm,项目名称:etcd-export,代码行数:61,代码来源:example_test.go

示例12: etcdRecordCheckin

// etcdRecordCheckin takes a server struct and stores it in Etcd as a
// json value
func (s *Server) etcdRecordCheckin() {
	if s.Hostname == "" {
		log.Printf("[WARNING] Unable to checkin server with Ip Address %s due to no hostname (can't resolve and wasn't supplied in JSON).", s.IpAddress)
		return
	}
	if *Verbose {
		log.Printf("connecting to: %s%s", clientConnectionSetup(), Endpoint)
	}
	client := etcd.NewClient(clientConnectionSetup())
	// first ensure the Endpoint is registered
	_, err := client.Get(Endpoint, false, false)
	if err != nil {
		_, err := client.SetDir(Endpoint, 0)
		if err != nil {
			log.Printf("[ERROR] Etcd SetDir Error: %s", err)
			return
		}
	}
	// generate json from the server struct
	json_value, err := json.Marshal(s)

	if err != nil {
		log.Printf("[ERROR] Json Marshal Error: %s", err)
		return
	}
	// now we set the value
	client.Set(Endpoint+"/"+s.Hostname, string(json_value), 0)
}
开发者ID:jbkc85,项目名称:matrixd,代码行数:30,代码来源:etcd_server_records.go

示例13: Init

func (w *watcher) Init(etcdURLS string) {
	w.client = etcd.NewClient(strings.Split(etcdURLS, ","))

	if len(w.etcdMachines) > 0 {
		w.client.SetCluster(w.etcdMachines)
	}
}
开发者ID:garciademarina,项目名称:active-proxy,代码行数:7,代码来源:watcher.go

示例14: NewClient

func NewClient(key string) *Client {
	etcd := etcd.NewClient([]string{etcdMachine})

	etcd.SyncCluster()

	return &Client{Key: key, etcd: etcd}
}
开发者ID:albertrdixon,项目名称:romulus,代码行数:7,代码来源:client.go

示例15: NewEtcd

func NewEtcd(prefixKey string, config *EtcdConfig) (*Etcd, error) {
	var (
		client *etcd.Client
		err    error
	)

	if config.CertFile != "" && config.KeyFile != "" {
		if client, err = etcd.NewTLSClient(config.Machines, config.CertFile, config.KeyFile, config.CaFile); err != nil {
			Logger.Error("Failed to connect to Etcd. Error: %+v.", err)
			return nil, err
		}
	} else {
		client = etcd.NewClient(config.Machines)
	}

	// Set the default value if not provided.
	if config.EtcdConsistency == "" {
		config.EtcdConsistency = etcd.STRONG_CONSISTENCY
	}

	if err = client.SetConsistency(config.EtcdConsistency); err != nil {
		Logger.Error("Failed to set Etcd consitency. Error: %+v.", err)
		return nil, err
	}

	return &Etcd{client: client, prefixKey: prefixKey}, nil
}
开发者ID:yonglehou,项目名称:maestro,代码行数:27,代码来源:etcd.go


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