本文整理匯總了Golang中github.com/flynn/flynn/discoverd/client.Service函數的典型用法代碼示例。如果您正苦於以下問題:Golang Service函數的具體用法?Golang Service怎麽用?Golang Service使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了Service函數的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: main
func main() {
var config Config
config.Backend.Type = "vxlan"
if backend := os.Getenv("BACKEND"); backend != "" {
config.Backend.Type = backend
}
config.Network = os.Getenv("NETWORK")
if config.Network == "" {
config.Network = "100.100.0.0/16"
}
flag.StringVar(&config.SubnetMin, "subnet-min", "", "container network min subnet")
flag.StringVar(&config.SubnetMax, "subnet-max", "", "container network max subnet")
flag.UintVar(&config.SubnetLen, "subnet-len", 0, "container network subnet length")
flag.UintVar(&config.Backend.VNI, "vni", 0, "vxlan network identifier")
flag.UintVar(&config.Backend.Port, "port", 0, "vxlan communication port (UDP)")
flag.Parse()
// wait for discoverd to come up
status, err := cluster.WaitForHostStatus(os.Getenv("EXTERNAL_IP"), func(status *host.HostStatus) bool {
return status.Discoverd != nil && status.Discoverd.URL != ""
})
if err != nil {
log.Fatal(err)
}
// create service and config if not present
client := discoverd.NewClientWithURL(status.Discoverd.URL)
if err := client.AddService(serviceName, nil); err != nil && !hh.IsObjectExistsError(err) {
log.Fatalf("error creating discoverd service: %s", err)
}
data, err := json.Marshal(map[string]Config{"config": config})
if err != nil {
log.Fatal(err)
}
err = client.Service(serviceName).SetMeta(&discoverd.ServiceMeta{Data: data})
if err != nil && !hh.IsObjectExistsError(err) {
log.Fatalf("error creating discoverd service metadata: %s", err)
}
flanneld, err := exec.LookPath("flanneld")
if err != nil {
log.Fatal(err)
}
if err := syscall.Exec(
flanneld,
[]string{
flanneld,
"-discoverd-url=" + status.Discoverd.URL,
"-iface=" + os.Getenv("EXTERNAL_IP"),
"-http-port=" + os.Getenv("PORT"),
fmt.Sprintf("-notify-url=http://%s:1113/host/network", os.Getenv("EXTERNAL_IP")),
},
os.Environ(),
); err != nil {
log.Fatal(err)
}
}
示例2: newTest
func newTest(t *testing.T) (s *test) {
defer func() {
if t.Failed() {
s.cleanup()
t.FailNow()
}
}()
client, killDiscoverd := testutil.BootDiscoverd(t, "")
serviceName := "flannel-test"
if err := client.AddService(serviceName, nil); err != nil {
t.Errorf("error adding service: %s", err)
}
service := client.Service(serviceName)
events := make(chan *discoverd.Event)
stream, err := service.Watch(events)
if err != nil {
t.Errorf("error creating watch: %s", err)
}
data := []byte(`{"config":{"network": "10.3.0.0/16"}}`)
if err := service.SetMeta(&discoverd.ServiceMeta{Data: data}); err != nil {
t.Errorf("error setting meta: %s", err)
}
registry, err := NewRegistry(client, serviceName)
if err != nil {
t.Errorf("error creating registry: %s", err)
}
return &test{
T: t,
client: client,
service: service,
events: events,
registry: registry,
cleanup: func() {
stream.Close()
killDiscoverd()
},
}
}
示例3: ServiceLeader
// ServiceLeader returns the leader for a service.
func (s *ProxyStore) ServiceLeader(service string) (*discoverd.Instance, error) {
host := s.Peers[rand.Intn(len(s.Peers))]
client := discoverd.NewClientWithURL("http://" + host)
return client.Service(service).Leader()
}